programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Paul Clapham
• Ron McLeod
• Tim Cooke
• Junilu Lacar
Sheriffs:
• Rob Spoor
• Devaka Cooray
• Jeanne Boyarsky
Saloon Keepers:
• Jesse Silverman
• Stephan van Hulst
• Tim Moores
• Carey Brown
• Tim Holloway
Bartenders:
• Jj Roberts
• Al Hobbs
• Piet Souris

# int to float 16777217

Ranch Hand
Posts: 1392
• Number of slices to send:
Optional 'thank-you' note:
I have been asked to explain this statement
"A float cannot hold the integer 16777217, because the significand is 24 bits."
Step 1. Collect some data.

Here is the floating point 32-bit representation (leading 0�s dropped)
16777210, 1001011011111111111111111111010
16777211, 1001011011111111111111111111011
16777212, 1001011011111111111111111111100
16777213, 1001011011111111111111111111101
16777214, 1001011011111111111111111111110
16777215, 1001011011111111111111111111111
16777216, 1001011100000000000000000000000
16777217, 1001011100000000000000000000000
[ September 09, 2003: Message edited by: Marlene Miller ]

Marlene Miller
Ranch Hand
Posts: 1392
• Number of slices to send:
Optional 'thank-you' note:
Step 2. Let�s analyze the floating point representation of 16777215.
16777215 1001011011111111111111111111111
Separate bits into 1-bit sign, 8-bit exponent and 23-bit signficand.
0 10010110 111 1111 1111 1111 1111 1111
Compute exponent. (127 means 2^0, 128 means 2^1, 126 means 2^-1)
exponent 10010110, 128 + 16 + 6 = 127 + 23, 2^23
Insert implicit leading 1. before signficand.
1.111 1111 1111 1111 1111 1111 * 2^23 ==
1111 1111 1111 1111 1111 1111

16777215, 111111111111111111111111
[ September 09, 2003: Message edited by: Marlene Miller ]

Marlene Miller
Ranch Hand
Posts: 1392
• Number of slices to send:
Optional 'thank-you' note:
Let�s analyze the floating point representation of 16777216.
16777216 1001011100000000000000000000000
0 10010111 000 0000 0000 0000 0000 0000
exponent 10010111, 128 + 16 + 7 = 127 + 24, 2^24
1.000 0000 0000 0000 0000 0000 * 2^24 ==
1 0000 0000 0000 0000 0000 0000

16777216, 1000000000000000000000000
[ September 09, 2003: Message edited by: Marlene Miller ]

Marlene Miller
Ranch Hand
Posts: 1392
• Number of slices to send:
Optional 'thank-you' note:
Step 3. Let�s convert the integer 16777217 to a float.

16777217 == binary 1000000000000000000000001
1 0000 0000 0000 0000 0000 0001 ==
1.0000 0000 0000 0000 0000 0001 * 2^24
The significand of this number is 24 bits. But the signficand of a float is only 23 bits. This number will not fit into a float.
[ September 09, 2003: Message edited by: Marlene Miller ]

Marlene Miller
Ranch Hand
Posts: 1392
• Number of slices to send:
Optional 'thank-you' note:
I learned about floating point representation from Computer Organization & Design, The Hardware/Software Interface by David A. Patterson and John L. Hennessy, section 4.8

Greenhorn
Posts: 26
• Number of slices to send:
Optional 'thank-you' note:
Thanks Marlene.

mister krabs
Posts: 13974
• Number of slices to send:
Optional 'thank-you' note: