Let F be a proper decimal fraction. The binary representation of F is:
The most significant bit of F, , may be obtained by multiplying F by 2:
The product 2F is the sum of and a proper fraction. If 2F 1 then = 1. Otherwise = 0.
After is determined, the process may be repeated on the resulting proper fraction to determine the other bits, as shown below:
I := 0 ; repeat I := I - 1 ; F := 2 * F ; if ( F >= 1 ) then begin B[I] = 1 ; F := F - 1 ; end ; else B[I] = 0 ; until ( F = 0 ) ;
Note that the preceding Pascal program fragment is presented as a description of the conversion algorithm, not as a computational procedure.
Example:
Convert decimal 0.375 to a binary fraction.
Binary representation: .011