decimal-binary
decimal-binary
2. Start by comparing the number you want to convert to the value leftmost column. If you’ve set
up the table correctly, it should be less than the column value, so put a 1 in the column.
Base 10 vs. Base 2 3. Add up the values of all the columns you’ve put 1’s in so far. This is your running total. Take
the running total and add the value of the next column. If the result is less than the number you
We’re used to thinking about numbers in base 10. People probably started using base 10 because we want to convert, put a 1 in this column. If the result is greater than the number you want to
have 10 fingers so it’s easiest for us to count in groups of 10. In a base 10 (or decimal) number, each convert, put a 0 in this column.
column in the number stands for a power of 10. Numbers have a 1’s column (= 100 ), 10’s column (=
101 ), 100’s column(= 102 ), etc. We write numbers with the most significant column (the one with the 4. Repeat the previous step until all columns are filled.
highest value) at the left. We can determine the value of number by multiplying the digit in the column
by how much the column is worth:
Decimal number: 87
1000 100 10 1 64 32 16 8 4 2 1
---------------- --------------------------
2 0 3 6 1 (64 < 87 ? yes)
0 (64 + 32 < 87 ? no)
Total: 2 * 1000 + 0 * 100 + 3 * 10 + 6 * 1 = 2036 1 (64 + 16 < 87 ? yes)
0 (64 + 16 + 8 < 87 ? no)
1 (64 + 16 + 4 < 87 ? yes)
We’re all used to working with base 10, but because information in a computer is stored in bits (just 0 1 (64 + 16 + 4 + 2 < 87 ? yes)
or 1, so it’s kind of like just having two fingers to count on), it’s easiest to work in base 2. In a base 2 1 (64 + 16 + 4 + 2 + 1 = 87, yes, done)
(or binary) number, each column stands for a power of 2: 20 (= 1), 21 (= 2), 22 (= 4), 23 (= 8), etc.
Binary number: 1010111
16 8 4 2 1
Decimal number: 105
------------------
1 0 1 1 0
64 32 16 8 4 2 1
--------------------------
Total: 1 * 16 + 0 * 8 + 1 * 4 + 1 * 2 + 0 * 1 = 22
1 (64 < 105 ? yes)
1 (64 + 32 < 105 ? yes)
0 (64 + 32 + 16 < 105 ? no)
We will consider two methods for converting between decimal and binary numbers, the table method 1 (64 + 32 + 8 < 105 ? yes)
and the division/multiplication by 2 method. 0 (64 + 32 + 8 + 4 < 105? no)
0 (64 + 32 + 8 + 2 < 105? no)
Table Method 1 (64 + 32 + 8 + 1 = 105, yes, done)
1. Create a table whose leftmost column is the greatest power of 2 less than the number you want
to convert. If the number is between 64 and 127, the leftmost column will be 64. If the number is Binary to Decimal with a Table
between 128 and 255, the leftmost column will be 128. Each column in the table is a power of 2.
The rightmost column is 20 (= 1), the next one to the left is 21 (= 2), the next is 22 (= 4), etc. 1. Create a table with enough columns for your binary number. (See instructions in the previous
Instead of thinking about powers of 2, you can just think about doubling each number to get the section.)
value for the next column to the left. This will typically look like:
64 32 16 8 4 2 1
64 32 16 8 4 2 1 --------------------------
--------------------------
2. Fill in the binary number in the table making sure that the rightmost digit is aligned under 1.
3. For each column containing a 1, take the value of that column (e.g., 64, 32, etc.) and add it to Binary to Decimal: Multiply by 2
the total.
1. Start with 0 as the result. Add to 0 the digit from the leftmost column in the binary number.
Binary number: 1010111
2. Take the result, multiply it by 2, and add the next digit following left-to-right in the binary
64 32 16 8 4 2 1 number.
--------------------------
3. Repeat Step 2 until you have used all digits in the binary number. The final result is your answer.
1 0 1 0 1 1 1
Total: 64 + 16 + 4 + 2 + 1 = 87
Binary number:
64 32 16 8 4 2 1 0 + 1 = 1 0 + 1 = 1
-------------------------- 1 * 2 + 0 = 2 1 * 2 + 1 = 3
1 1 0 1 0 0 1 2 * 2 + 1 = 5 3 * 2 + 0 = 6
5 * 2 + 0 = 10 6 * 2 + 1 = 13
Total: 64 + 32 + 8 + 1 = 105 10 * 2 + 1 = 21 13 * 2 + 0 = 26
21 * 2 + 1 = 43 26 * 2 + 0 = 52
43 * 2 + 1 = 87 52 * 2 + 1 = 105
Division/Multiplication by 2 Method
Decimal number:
Decimal to Binary: Divide by 2
87 105
1. Take the decimal number and divide it by two keeping track of the remainder (instead of decimal
place). For example, 10 / 2 is 5 r 0. 11 / 2 is 5 r 1. The result for both is 5. The remainder for
10 / 2 is 0 and the remainder for 11 / 2 is 1.
2. Take the result and divide it by two in the same way, always keeping track of the remainder.
3. Repeat Step 2 until you reach a result of 0. Your last step should always look like 1 / 2 = 0 r 1.
4. Read the remainders (all 0 or 1) off in reverse order starting at the bottom with the one you just
finished. This is the answer.