Binary Lesson 3 – Converting Decimal to Binary

September 1, 2014

lesson03How can we convert a decimal number, such as 195, into a binary number that consists of nothing more than a pattern of ones and zeros?

Decimal and Binary are two completely different number systems limited by their own sets of digits, so we must perform a conversion in order to represent the same value in each.

The resulting values will appear different in each number system because of digit limitations. For example, the value 192 appears as 192 in decimal because base 10 allows for ten unique digits 0 through 9. However, the value 192 is represented as 11000000 (not 11,000,000) in binary because base 2 is limited to zeros and ones.

11000000 looks nothing like 192, but both represent the same value. How did we achieve this?

In this lesson we will see how to convert decimal to binary using two methods: division (elaborate) and subtraction (simpler).

Division Method

To form the binary value of a decimal number, start from the most significant bit position in the binary place value chart, and attempt to divide the value of each place into the number while recording the remainder. Eventually, the original number will be reduced to zero after the ones place. Record a 1 in each place whose value divides into the remaining value whether there is a remainder or not, and record a 0 for each place whose value is too large to divide into the number.

  1. Start from the most significant binary place value
  2. Attempt to divide each place value into the remaining decimal number
  3. If the place value is larger than the existing decimal number, record 0 in the binary place value chart
  4. Otherwise, divide and record a 1 in the binary place value chart. Keep the remainder
  5. Proceed to the next less-significant binary place value using the remainder from step 4
  6. Repeat until all place values are filled

 

Convert Decimal 195 Into Binary

Let us try converting 195 (base 10) into binary (base 2). We start by writing a binary place value chart for eight places because 255 is the greatest value that can be represented with eight bits, and 195 is less than 255 yet greater than 127 (seven bits). Review Lesson 2 for details about creating a place value chart.

Binary Place Value Chart to Eight Places:

Most significant bit --> 128  64  32  16  8  4  2  1 <-- Least significant bit

Begin with 128, which is the most significant bit. Does 128 divide into 195?

195 / 128 = Remainder 67

Yes, it does, and the division produces a result of 67. Record a 1 in the 128 place and keep the 67. Move to the next place value to the right, which is 64. Does 64 divide into 67?

67 / 64 = Remainder 3

64 divides into 67, so we record a 1 in the 64 place.

 

128  64  32  16  8  4  2  1
 1   1

 

[ SIDENOTE: Modulus ]

When we divide one number, called the dividend, by another number, called the divisor, we produce a result called the quotient. Any part that does not divide evenly and is “left over” from the division is called the remainder.

11 / 5 = 2 Remainder 1

In this example, 11 is the dividend, 5 is the divisor, 2 is the quotient, and 1 is the remainder.

When we perform division where we discard the quotient but keep the remainder, we are performing what is called a modulus operation. This is common in computer programming, and the modulus operator is represented by the % (percent) symbol.

If we want to specify a division operation that records the remainder, we would write

11 % 5 = 1

In the decimal to binary conversion, we are performing modulus division using the binary place value as the divisor in order to obtain the value for the next division.

195 % 128 = 67
67 % 64 = 3

[ End Sidenote ]

 

Proceed to the 32 place. Does 32 divide into 3 and still produce a positive, whole number value? No, it does not. In fact, if the dividend is larger than the divisor, we can skip it. Record a 0 in the place whose value does not divide into the current remainder. While 3 divided by 32 equals .09375, we cannot use it. We must use whole numbers.

128  64  32  16  8  4  2  1
  1   1   0

Keep the 3 and continue testing it against each place value to the right. 16, 8, and 4 do not divide into 3, so record a 0 in each of these places.

128  64  32  16  8  4  2  1
  1   1   0   0  0  0

Will 2 divide into 3?

3 / 2 = 1 remainder 1

Record a 1 in the 2 place and keep the remainder 1 for the final test against the ones place.

128  64  32  16  8  4  2  1
  1   1   0   0  0  0  1

Will 1 divide into 1?

1 / 1 = 1 remainder 0

Yes, 1 divides into itself evenly, so we record a 1 in the ones place.

128  64  32  16  8  4  2  1
  1   1   0   0  0  0  1  1

The remainder should be zero at this point. If not, then this indicates that there was an error in the calculation somewhere and the binary result is not correct. Think of this as a form of built-in error checking.

The byte 11000011 is the binary representation of the decimal number 195.

11000011 (base 2) = 10 (base 10)

Subtraction Method

If division is too confusing to grasp, we can achieve the same conversion using subtraction. This is mostly the same process as division, but instead of dividing, we subtract. Record a 1 for each place value that results in a positive whole number. If the result is negative, record a 0 in its place. Use the difference (the result of subtraction) for the next calculation. Continue from left to right until 1 is computed.

Convert Decimal 195 Into Binary

Begin with 128. Does 128 subtract from 195 and still produce a positive result?

195 - 128 = 67

Yes, it does, and 67 is the difference. So, we record a 1 under the 128 place and keep the 67.

128  64  32  16  8  4  2  1
  1

Does 64 subtract from 67?

67 - 64 = 3

Again, we have a positive whole number difference. Record a 1 in the 64 place, and keep the 3.

128  64  32  16  8  4  2  1
  1   1

Does 32 subtract from 3 and still produce a positive whole number?

3 - 32 = -29

No, it does not. 3 minus 32 results in -29. This is a negative number, so we must discard it. In fact, if the place value is greater than the current value (3, so far, in this case) of the place value in the chart, we can skip it and record 0 in its place. Since 32 is greater than 3, we record a 0 in the 32 place.

128  64  32  16  8  4  2  1
  1   1   0

Test 16, 8, and 4 separately in the same way. All are greater than 3. None subtract from 3 without producing negative values, so we record a 0 for each of their places.

128  64  32  16  8  4  2  1
  1   1   0   0  0  0

Will 2 subtract from 3?

3 - 2 = 1

Yes, so we record a 1 in the twos place and keep the resulting 1.

128  64  32  16  8  4  2  1
  1   1   0   0  0  0  1

Perform the final subtraction.

1 - 1 = 0

Since 1 subtracts from 1, we record a one in the ones place.

128  64  32  16  8  4  2  1
  1   1   0   0  0  0  1  1

The result is the same 11000011 as produced by the division method. Convert from binary to decimal to double check the answer.

128  64  32  16  8  4  2  1
  1   1   0   0  0  0  1  1
128 + 64 + 2 + 1 = 195 (base 10, decimal)

 

Practice

Practice helps reinforce the conversion concept. Convert these decimal numbers into binary using pencil and paper, not a calculator:

  1. 195
  2. 3
  3. 16
  4. 192
  5. 255
  6. 256
  7. 67
  8. 38
  9. 1000 (This looks like 1000 in binary, but this is the decimal number 1,000)
  10. 121

Answers

  1. 11000011
  2. 11
  3. 10000
  4. 11000000
  5. 11111111
  6. 100000000
  7. 1000011
  8. 100110
  9. 1111101000
  10. 1111001

Again, perform the calculations on paper in order to understand the procedure since calculators will deprive us of understanding at this point. For faster conversions, memorize the binary place value table up to sixteen places and group bits into chunks of four or eight. We want to develop the conversion skill, not just the answer.

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: