Binary Timer Appendix

Base Conversion with Method 1 (Short Division by Two with Remainder)

First a reminder how to extract each digit in base 10 system.

Example: If you were trying to extract the digits of a number, say, 527 in base 10, you would take the following steps.
Decimal Digit Extraction
(Recall that the floor() function rounds a number down to the closest integer.)

  1. Find the “ones” digit, via remainder in 527 divided by 10:
    527 mod 10 = 7
    Get quotient:
    floor(527/10)= 52
  2. Repeat, find the “tens” digit, via remainder in 52 divided by 10:
    52 mod 10 = 2
    Get quotient:
    floor(52/10) = 5
  3. Repeat, find the “hundreds” digit, via remainder in 5 divided by 10:
    5 mod 10 = 5
    Get quotient:
    floor(5/10) = 0

This is where we stop. So 527= 5(100) + 2(10) + 7(1)

Note with the algorithm we extracted the digits right to left. (7 first, 2 next, 5 last)

Example: If you apply a similar procedure to get the binary representation of a number, say, 25, you would take the following steps.
Binary Digit Extraction

  1. Find the “ones” digit, via remainder in 25 divided by 2:
    25 mod 2 = 1
    Get quotient:
    floor(25/2)= 12
  2. Repeat, find the “twos” digit, via remainder in 12 divided by 2:
    12 mod 2= 0
    Get quotient:
    floor(12/2)= 6
  3. Repeat, find the “fours” digit, via remainder in 6 divided by 2:
    6 mod 2= 0
    Get quotient:
    floor(6/2)= 3
  4. Repeat, find the “eights” digit, via remainder in 3 divided by 2:
    3 mod 2= 1
    Get quotient:
    floor(3/2)= 1
  5. Repeat, find the “sixteens” digit, via remainder in 1 divided by 2:
    1 mod 2= 1
    Get quotient:
    floor(1/2)= 0

This is where we stop. Note with the algorithm again we extracted the digits right to left.

So 25= 1(16) + 1(8)+ 0(4) + 0(2) + 1(1) = (11001)2

Using these examples come up with an algorithm to represent any base 10 number in base 2.

Base conversion with Method 2: (Descending Powers of Two and Subtraction)

Example: If you are trying to get the binary representation of a number, say, 25, you would take the following steps.

Is 24 =16 contained in 25? Yes, write 1.
25-16=9
Is 23 = 8 contained in  9? Yes, write 1.
9-8=1
Is 22 = 4 contained in  1? No,  write 0.
Is 21 = 2 contained in  1? No,  write 0.
Is 20 = 1 contained in  1? Yes, write 1.
1-1=0  Done.