The solution uses an additonal row to transform the binary number. A single one is written on the additional row in the beginning.

Steps:

  1. Read current bit of the binary number.
  2. If the bit read is a one, go to step 3, otherwise go to step 4,
  3. Copy the ones in the help row to the end of the output (blue states).
  4. Double the ones in the help row (green states)
  5. Go to the next bit of the binary number. Return to step 1 if there is a bit left.