created: 07/15/2015; improved 04/10/16

Decimal Representation to Binary


Positive Integer:
bit = Number Mod Two
quotient = Number Div Two
Bit String
number = quotient

To start: Enter a decimal representation of a positive integer in the "Positive Integer" box.

Then: Click "Initialize" to assign the integer to "number".

Then: Click "Divide by Two" to compute the quotient and remainder. The remainder will be 0 or 1. That bit is copied to the left of the bit string.

Click "Repeat" to go through the cycle again. Quit when the number has been reduced to zero.

The algorithm is:

number = positive integer ;
bitstring = ""

while (number > 0 )
  bit      = number mod 2 ;
  quotient = number div 2 ;
  put bit to the left of any previous bits in the bitstring ;
  number = quotient ;

go to home page     Return to Home