Click New Example to start working through an example. Click on the steps of the algorithm to see the values of the variables in each step. First click on step 1. and then on the following steps in the order of execution.
New Example Restart Example
Algorithm. Conversion to base 2 representation.
Input:A natural number a
Output:The digits r0, r1, r2,...,rn of the base 2 representation of a
such that a = rn2n +... + r222 + r12 + r0.
  1. let i := (-1)
  2. let q := a
  3. repeat
    1. let i := i + 1
    2. let ri := q mod 2
    3. let q := q div 2
  4. until q = 0
  5. return r0,...,ri