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:

displaymath346

where tex2html_wrap_inline264 = 0 or 1. Observe that D is even when tex2html_wrap_inline268 = 0, and that D is odd when tex2html_wrap_inline268 = 1.

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

displaymath347

displaymath348

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

displaymath349

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

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:

tabular124

The binary representation is 1011111.



CS 301 Class Account
Tue Sep 15 00:04:01 ADT 1998