• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Strange issue when converting from hex to float
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Strange issue when converting from hex to float


  • Subject: Re: Strange issue when converting from hex to float
  • From: Steve Bird <email@hidden>
  • Date: Thu, 21 Jul 2005 13:20:21 -0400


On Jul 21, 2005, at 12:54 PM, Ian was here wrote:


long alphaComp = strtol( alphaValue, NULL, 16 );

The following code segment always returns zero!!??

// Convert each decimal number to float.

float fAlpha = alphaComp / 255L;

Let's see - what are we doing? alphaComp was previously defined as a LONG. So we are dividing a LONG by a LONG - that's an integer division. Since the value is most likely less than 255, we get zero. Then (and only then) we convert that integer 0 to a float 0.0. Yep. It's doing what you tell it to.

Perhaps you could try:
float            fAlpha = alphaComp / 255.0;

or:
float            fAlpha = (float)alphaComp / 255L;

----------------------------------------------------------------
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
www.Culverson.com                     (toll free) 1-877-676-8175


_______________________________________________ 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
References: 
 >Strange issue when converting from hex to float (From: Ian was here <email@hidden>)

  • Prev by Date: Re: Strange issue when converting from hex to float
  • Next by Date: getting serial data
  • Previous by thread: Re: Strange issue when converting from hex to float
  • Next by thread: Re: Strange issue when converting from hex to float
  • Index(es):
    • Date
    • Thread