Velocity Reviews > 8.8 notation....

# 8.8 notation....

Darrell Grainger
Guest
Posts: n/a

 10-01-2003
On Wed, 1 Oct 2003, John T. wrote:

> I have a number in 8.8 notation that I wish to convert to a float.......
> 8.8 notation is a 16 bit fixed notation, so:
> 0xFF11 is the number 255.17
> 0x0104 is the number 1.4
> 0x2356 is the number 35.86
> and so on....
> Any ideas on how to convert this into a float?

Your examples don't tell me how I deal with numbers like:

0x0064

Is this 0.100 or is this 1.00?

Obviously, the first step is seperating the number into the whole number
and the fraction:

/* let n be the number we are dealing with */
float result;
int whole = (n >> & 0xff;
int fraction = n & 0xff;

If the first method is the desired result you would need:

if(fraction > 99)
result = whole + fraction/100.0;
else
result = whole + fraction/10.0;

If the second method is the desired result you would need:

result = whole + fraction/10.0;

--
Send e-mail to: darrell at cs dot toronto dot edu
Don't send e-mail to http://www.velocityreviews.com/forums/(E-Mail Removed)

Christopher Benson-Manica
Guest
Posts: n/a

 10-01-2003
Joona I Palaste <(E-Mail Removed)> spoke thus:

> This would make 0x0101 and 0x010A the same thing, yesno?

Hm, yes, if he's trying to convert these to floats.

> And there
> would be no way to represent 1.01, yesno?

Again, yes, although I'm not sure he wants to. The format itself makes sense
(although I don't know what one would use it for).

> Either his "." means a different thing than the fraction separator in
> decimal, he has made a few typos, or he doesn't understand his own
> function.

I'm betting on the first one, but I'm not sure...

--
Christopher Benson-Manica | Jumonji giri, for honour.
ataru(at)cyberspace.org |

David Rubin
Guest
Posts: n/a

 10-01-2003
Christopher Benson-Manica wrote:
>
> Joona I Palaste <(E-Mail Removed)> spoke thus:
>
> > This would make 0x0101 and 0x010A the same thing, yesno?

>
> Hm, yes, if he's trying to convert these to floats.
>
> > And there
> > would be no way to represent 1.01, yesno?

>
> Again, yes, although I'm not sure he wants to. The format itself makes sense
> (although I don't know what one would use it for).

The format is kind of lame IMO. Why not use 0x[0-9A-Z]{2}[0-9]{2} to
represent 000.00 to 255.99? This is only slightly less efficient, but
much more straightforward.

/david

--
Andre, a simple peasant, had only one thing on his mind as he crept
along the East wall: 'Andre, creep... Andre, creep... Andre, creep.'
-- unknown

Joona I Palaste
Guest
Posts: n/a

 10-01-2003
David Rubin <(E-Mail Removed)> scribbled the following:
> Christopher Benson-Manica wrote:
>> Joona I Palaste <(E-Mail Removed)> spoke thus:
>> > This would make 0x0101 and 0x010A the same thing, yesno?

>>
>> Hm, yes, if he's trying to convert these to floats.
>>
>> > And there
>> > would be no way to represent 1.01, yesno?

>>
>> Again, yes, although I'm not sure he wants to. The format itself makes sense
>> (although I don't know what one would use it for).

> The format is kind of lame IMO. Why not use 0x[0-9A-Z]{2}[0-9]{2} to
> represent 000.00 to 255.99? This is only slightly less efficient, but
> much more straightforward.

Because (10+26) squared is 1296, not 256?

--
/-- Joona Palaste ((E-Mail Removed)) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"A computer program does what you tell it to do, not what you want it to do."
- Anon

Keith Thompson
Guest
Posts: n/a

 10-01-2003
Joona I Palaste <(E-Mail Removed)> writes:
> Christopher Benson-Manica <(E-Mail Removed)> scribbled
> the following:
> > Arthur J. O'Dwyer <(E-Mail Removed)> spoke thus:
> >> Wait a minute... I realized as soon as I sent that message
> >> that I can't think of *any* reasonable way to get 0x0104
> >> from the floating-point value 1.4! If 0x0104 is 1.4, then
> >> what's 1.04? And what does 0x0140 represent in your
> >> notation?

>
> > If I'm not mistaken, 0x0140 is 1.64 in his notation.

>
> Either his "." means a different thing than the fraction separator in
> decimal, he has made a few typos, or he doesn't understand his own
> function.

The OP wrote:
> 0xFF11 is the number 255.17
> 0x0104 is the number 1.4
> 0x2356 is the number 35.86

Assuming that 1.4 was a typo, and it should be 1.04, the notation
looks odd but consistent. The high-order 8 bits are the integer part;
the low-order 8 bits are the fractional part multiplied by 100.0
decimal. One advantage of such a notation is that it can represent
decimal fractions such as 0.1 or 0.01 exactly; of course, converting
to binary floating-point loses that property.

> This would make 0x0101 and 0x010A the same thing, yesno? And there
> would be no way to represent 1.01, yesno?

Nononono. 0x0101 is 1.01, and 0x010A is 1.10.

It would mean that 0x0164 and 0x0200 would both represent 2.00, but
presumably 0x0164 would be the canonical normalized representation.

I suggest we wait for the OP to come back and tell us what he really
meant.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"