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 11:50:28 -0700 (PDT)
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
Attachment:
convertHextToNSColor.sitx
Description: 1065542667-convertHextToNSColor.sitx
_______________________________________________
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