leodutra
12/23/2015 - 3:39 AM

Decimal to binary algorithm

Decimal to binary algorithm

number = positive integer ;
bitstring = ""

while (number > 0 )
{
  bit      = number mod 2 ; 
  quotient = number div 2 ; // or "n * 0.5" or "n >>> 1" (verify precision for large ints) 
  put bit to the left of any previous bits in the bitstring;
  number = quotient ;
}