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: Ian was here <email@hidden>
- Date: Fri, 22 Jul 2005 12:31:25 -0700 (PDT)
Man! Do I ever feel stupid!! I must have looked over
this code a zillion times and haden't noticed it. I
need to be more careful when copying and pasting
similar lines of code. This code works:
float fAlpha = alphaComp / 255.0f;
float fRed = redComp / 255.0f;
float fGreen = greenComp / 255.0f;
float fBlue = blueComp / 255.0f;
Thanks guys.
--- Will Mason <email@hidden> wrote:
> 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
>
>
____________________________________________________
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