View Full Version : Decimal to Binary
x_endlessrain_x
Jul22-04, 01:30 AM
hi!
does anybody know how to convert a fraction(deciaml) to Binary?
for example how can we convert 0.16 to Binary?
thx for helping
In a similar way you'd do for numbers > 0.
If we have 200, we can start by finding the largest power of 2 less than or equal to 200, namley 128, and we have 72 remaining. The largest power of 2 less than or equal to 72 is 64, with 8 remaining. The largest power of 2 less than or equal to 8 is 8, with zero remaining. With zero remaining, we stop. So, we have
1x128 + 1x64 + 0x32 + 0x16 + 1x8 + 0x4 + 0x2 + 0x1. In binary:
11001000.
Do the same for 0.16. The greatest power of 2 less than 0.16 is 2^{-3} = 1/8 = 0.125. This leaves 0.035 remaining. You might find yourself with a non-terminating binary representation. To start, you'll have 0.001... (I haven't figured out what will replace the "...", that's your job ;)).
x_endlessrain_x
Jul22-04, 01:54 AM
ok,i got it ! thx
Goalie_Ca
Jul22-04, 02:00 AM
http://research.microsoft.com/~hollasch/cgindex/coding/ieeefloat.html
This may also be what you want. It's an IEEE floating point standard.
vBulletin® v3.8.7, Copyright ©2000-2012, vBulletin Solutions, Inc.