5.2
Converting Decimal to Binary
Now this is the part where modular arithmetic comes in handy!
We know that if we compute any number (mod 2) it will either be 0 or 1, and so that’s
exactly what we use for converting decimal numbers to binary.
Basically, we compute our number (mod 2) and that will be our last digit. Then we compute
our quotient (mod 2) and place that as our 2
last digit, and so on until our quotient is 0.
For example: Converting 13 to binary form, we would do the following.
Now reading from the bottom up, 13 in decimal form is 1101 in binary form.
Note: Your last step should always be the same as the one above.
Exercise 6: Convert each of the following numbers to binary form.
(a) 76
(b) 193
(c) 97
(d) 255
76 = 2(38) + 0
193 = 2(96) + 1
97 = 2(48) + 1
255 = 2(127) + 1
38 = 2(19) + 0
96 = 2(48) + 0
48 = 2(24) + 0
127 = 2(63) + 1
19 = 2(9) + 1
48 = 2(24) + 0
24 = 2(12) + 0
63 = 2(31) + 1
9 = 2(4) + 1
24 = 2(12) + 0
12 = 2(6) + 0
31 = 2(15) + 1
4 = 2(2) + 0
12 = 2(6) + 0
6 = 2(3) + 0
15 = 2(7) + 1
2 = 2(1) + 0
6 = 2(3) + 0
3 = 2(1) + 1
7 = 2(3) + 1
1 = 2(0) + 1
3 = 2(1) + 1
1 = 2(0) + 1
3 = 2(1) + 1
1001100
1 = 2(0) + 1
1100001
1 = 2(0) + 1
11000001
11111111
7