Re: Strange issue when converting from hex to float
Re: Strange issue when converting from hex to float
- Subject: Re: Strange issue when converting from hex to float
- From: Will Mason <email@hidden>
- Date: Fri, 22 Jul 2005 12:03:01 -0700 (PDT)
I think the problem is that the result of the division is always
computed like this "(float)alphaComp / (float)255.0". You're never
actually using the values redComp, greenComp and blueComp. You must
always be testing with an alpha value of zero, so you never see
anything else after division. Here's the offending part of your code:
float fAlpha = (float)alphaComp / (float)255.0;
float fRed = (float)alphaComp / (float)255.0;
float fGreen = (float)alphaComp / (float)255.0;
float fBlue = (float)alphaComp / (float)255.0;
You might want to try using the color values where appropriate instead
of just the alpha value.
Will
--- Ian was here <email@hidden> wrote:
> Here's the run log output for my decimal numbers that
> were converted from hex:
>
> 2005-07-22 11:42:57.709 QwizdomInteract[6181] 0 255 32
> 254
>
>
> and here's the output after the division takes place:
>
> 2005-07-22 11:42:57.709 QwizdomInteract[6181] 0.000000
> 0.000000 0.000000 0.000000
>
>
> I've also confirmed these values in the debugger.
>
> Attached is the full method that I'm working on. All
> you need to do is pass in a string containing a hex
> value like so: [myClass
> convertHexToNSColor:@"#00FF20FE"];
>
>
> Thank you gentlemen for taking the time and effort to
> look into this matter. It's greatly appreciated. :-)
>
>
>
> --- Sherm Pendley <email@hidden> wrote:
>
> > On Jul 22, 2005, at 1:00 PM, Ian was here wrote:
> >
> > > I've tried all that before
> >
> > Sherm-Pendleys-Computer:~ sherm$ cat testop.c
> > #include <stdio.h>
> > #include <stdlib.h>
> >
> > int main(int argc, char **argv) {
> > long a = strtol("0xee", NULL, 16);
> >
> > float b = a/255L;
> > float c = a/255.0;
> >
> > printf("a=%d, b=%f, c=%f\n", a, b, c);
> > }
> > Sherm-Pendleys-Computer:~ sherm$ gcc -o testop
> > testop.c
> > Sherm-Pendleys-Computer:~ sherm$ ./testop
> > a=238, b=0.000000, c=0.933333
> >
> > Clearly, your bug lies elsewhere, not in the
> > division and assignment
> > statement.
> >
> > Double-check with the debugger and/or NSLog()s the
> > values being
> > passed to that. Also, double-check how you're
> > printing your output.
> > If you're printing the results later on, try
> > checking it immediately
> > after the division - it could be getting
> > overwritten.
> >
> > sherm--
> >
> > Cocoa programming in Perl:
> > http://camelbones.sourceforge.net
> > Hire me! My resume: http://www.dot-app.org
> >
> >
>
>
>
> ____________________________________________________
> Start your day with Yahoo! - make it your home page
> http://www.yahoo.com/r/hs
> > _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Cocoa-dev mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
>
> This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden