next up previous
Next: Fractions Up: Number Systems Previous: Number Table

Decimal to Binary Conversion

The division method calculates the least significant bit first.

Let D be a decimal number such that:

displaymath1217

where tex2html_wrap_inline1135 = 0 or 1. Observe that D is even when tex2html_wrap_inline1139 = 0, and that D is odd when tex2html_wrap_inline1139 = 1.

To find tex2html_wrap_inline1139 , divide D by 2 to obtain a quotient Q and a remainder R:

displaymath1218

displaymath1219

Thus, Q = D/2 and R = tex2html_wrap_inline1139 . Renumbering the summation, we obtain:

displaymath1220

The least significant bit of Q is now tex2html_wrap_inline1235 . Dividing Q by 2 now produces tex2html_wrap_inline1235 as the remainder. The division process is repeated on each quotient until Q = 0 to obtain all the tex2html_wrap_inline1135 .

The algorithm may be written in Pascal as follows:

        I := 0;
        Q := D;
        repeat
            B[I] := Q mod 2 ;
            Q := Q div 2 ; 
            I := I + 1 ;
        until Q = 0 ;

Conversion to base R is accomplished by successive divisions by R, instead of 2, in the above algorithm.

Example:

Convert 95 in base 10 to binary:

tabular403

The binary representation is 1011111.



Mitch Roth
Wed Oct 9 13:38:30 ADT 1996