 ## Introduction

Yesterday we discussed how to take a binary number (base 2) and convert it to a decimal number (base 10) (see Back to Basics: Converting Binary to Decimal Part 1 of 2).  Today we are going to do the opposite: convert a decimal number to a binary number. If you understood yesterday's post, this will be a breeze.

Definitions

Decimal

Decimal = base 10, which means there are 10 possible values when we use decimal to count.  Those values are 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9.  When we run out of values we repeat them.  Therefore, we go to 10 (repeats 0 and 1), 11 (repeats the 1s), 12 (repeats the 1 and 2)…  Fortunately, you already know decimal.

Binary

Binary = base 2, which means there are only 2 values. Another way to look at it is Bi = 2 as in bicycle (2 wheels), bifocal (2 lenses in your eye glasses), bimonthly (twice per month), binocular (handheld optical instrument with 2 small telescopes side by side)…

Bit

Bit is the smallest unit in the computer world.  It can only have a single value: 1 or 0.  It is designated by a lower case “b”.  For example Gb = Giga bit.  1 = a value of 1 and 0 = a value of 0.

Byte

A byte is 8 bits and is represented by a capital “B”.  For example GB = Giga Byte.

## Conversion

So, let’s start with the decimal values in an 8 bit byte

Decimal Value 128      64        32        16        8          4          2          1

When converting a decimal number to binary number we start at the left of the decimal value string of numbers (128) and work to the right. Let’s call the value for 128 position 1, the value for 64 position 2, 32 position 3, etc.

Position               1        2          3          4        5          6          7          8

Decimal Value 128      64        32        16        8          4          2          1

Binary Value

Starting at position 1 we ask the following question:

Is the decimal number we are converting to binary greater than (>), equal (=) to or less than (<) the decimal value?

• If the decimal number is > or = to the decimal value we place a 1 in the binary value for that position.
•  If the decimal number is < or 0 (zero) we put a 0 in the binary value for that position.

Let’s do an example to clarify this using the decimal number of 165.  Starting a position 1 we ask the following question

Is 165 >, = or < than 128?

In this case 165 is > than 128.  Therefore we place a 1 in the first position for the binary value.

Position               1        2          3          4        5          6          7          8

Decimal Value 128      64        32        16        8          4          2          1

Binary Value

The next step is to deduct the decimal value of 128 from the digital number of 165 to come up with the remainder.

165 Original Number We Are Converting

-   128 Decimal Value

37 The Remainder

Now we move on to position 2 and repeat the process.

Is 37 (The Remainder) >, = or < than 64?

Why 64?  Because that is the decimal value in position 2.

In this case 37 is < than 64.  Therefore we place a 0 in the binary value as shown below:

Position               1        2          3          4        5          6          7          8

Decimal Value 128      64        32        16        8          4          2          1

Binary Value        1

Now we move on to position 3.

Is 37 >, = or < than 32?

In this case 37 is > 32.  Therefore, we place a 1 in the binary value as shown below:

Position               1        2          3          4        5          6          7          8

Decimal Value 128      64        32        16        8          4          2          1

Binary Value        1        0          1

The next step is to deduct the decimal value of 32 from remainder of 37 to come up with the new remainder.

37 Remainder from Above

-    32 Decimal Value

5 New Remainder

Now we move on to position 4.

Is 5 (the new remainder) >, = or < than 16?

In this case 5 is < 16.  Therefore, we place a 0 in the binary value as shown below:

Position               1        2          3          4        5          6          7          8

Decimal Value 128      64        32        16        8          4          2          1

Binary Value        1        0          1          0

Now we move on to position 5.

Is 5 >, = or < than 8?

In this case 5 is < 8.  Therefore, we place a 0 in the binary value as shown below:

Position               1        2          3          4        5          6          7          8

Decimal Value 128      64        32        16        8          4          2          1

Binary Value        1        0          1          0        0

Now we move on to position 6.

Is 5 >, = or < than 4?

In this case 5 is > 4.  Therefore, we place a 1 in the binary value as shown below:

Position               1        2          3          4        5          6          7          8

Decimal Value 128      64        32        16        8          4          2          1

Binary Value        1        0          1          0        0         1

The next step is to deduct the decimal value 4 from the digital value remainder of 5 to come up with the new remainder.

5 Remainder from Above

-      4 Decimal Value

1 New Remainder

Now we move on to position 7.

Is 1 (the new remainder) >, = or < than 2?

In this case 1 is < 2.  Therefore, we place a 0 in the binary value as shown below:

Position               1        2          3          4        5          6          7          8

Decimal Value 128      64        32        16        8          4          2          1

Binary Value        1        0          1          0        0          1          0

Now we move on to position 8.

Is 1 >, = or < than 1?

In this case 1 is = 1.  Therefore, we place a 1 in the binary value as shown below:

Position               1        2          3          4        5          6          7          8

Decimal Value 128      64        32        16        8          4          2          1

Binary Value        1        0          1          0        0          1          0          1

The next step is to deduct the decimal value 1 from the digital value remainder of 1 to come up with the new remainder.

1 Remainder from Above

-      1 Decimal Value

0 New Remainder

Once we get to 0 we are done.

To check our work all we have to do is add up the decimal values where there is a 1 in the binary value (128 + 32 + 4 + 1 = 165).  It worked!!!!!!!

Let’s do one more using the decimal number of 202.  Starting a position 1 we ask the following question

Is 202 >, = or < than 128

In this case 202 is > 128.  Therefore, we place a 1 in the binary value as shown below:

Position               1        2          3          4        5          6          7          8

Decimal Value 128      64        32        16        8          4          2          1

Binary Value        1

The next step is to deduct the decimal value of 128 from the digital value of 165 to come up with the remainder.

202 Original Number We Are Converting

-   128 Decimal Value

74 Remainder

Now we move on to position 2 and repeat the process.

Is 74 (the remainder from above) >, = or < than 64?

Why 64?  Because that is the decimal value in position 2.

In this case 74 is > 64.  Therefore, we place a 1 in the binary value as shown below:

Position               1        2          3          4        5          6          7          8

Decimal Value 128      64        32        16        8          4          2          1

Binary Value        1        1

The next step is to deduct the decimal value of 64 from the digital value of 74 to come up with the remainder.

74 Remainder From Above

-     64 Digital Value

10 New Remainder

Now we move on to position 3.

Is 10 >, = or < than 32?

In this case 10 < 32.  Therefore, we place a 0 in the binary value as shown below:

Position               1        2          3          4        5          6          7          8

Decimal Value 128      64        32        16        8          4          2          1

Binary Value        1        1          0

Now we move on to position 4.

Is 10 >, = or < than 16?

In this case 10 is < 16.  Therefore, we place a 0 in the binary value as shown below:

Position               1        2          3          4        5          6          7          8

Decimal Value 128      64        32        16        8          4          2          1

Binary Value        1        1          0          0

Now we move on to position 5.

Is 10 >, = or < than 8?

In this case 10 is > 8.  Therefore, we place a 1 in the binary value as shown below:

Position               1        2          3          4        5          6          7          8

Decimal Value 128      64        32        16        8          4          2          1

Binary Value        1        1          0          0        1

The next step is to deduct the decimal value of 8 from the digital value of 10 to come up with the remainder.

10 Remainder from Above

-       8 Decimal Value

2 New Remainder

Now we move on to position 6.

Is 2 >, = or < than 4?

In this case 2 is < 4.  Therefore, we place a 0 in the binary value as shown below:

Position               1        2          3          4        5          6          7          8

Decimal Value 128      64        32        16        8          4          2          1

Binary Value        1        1          0          0        1          0

Now we move on to position 7.

Is 2 >, = or < than 2?

In this case 2 = 2.  Therefore, so we place a 1 in the binary value as shown below:

Position               1        2          3          4        5          6          7          8

Decimal Value 128      64        32        16        8          4          2          1

Binary Value        1        1          0          0        1          0          1

The next step is to deduct the decimal value of 8 from the digital value of 10 to come up with the remainder.

2 Remainder From Above

-       2 Digital Value

0 New Remainder

Once we get to 0 the remaining positions are 0s

Thus, our final result is

Position               1        2          3          4        5          6          7          8

Decimal Value 128      64        32        16        8          4          2          1

Binary Value        1        1          0          0        1          0          1         0

To check our work all we have to do is add up the decimal values where there is a 1 in the binary value (128 + 64 + 8 + 2 = 202).

Now let’s watch a 5 minute video by Abigail Bornstein (LinkedIn Account) as she describes how to from decimal to binary.

Now let practice with converting 25 binary combinations to decimal.  The answers are below.

Hint: 1111 is the same as 00001111.  It is standard practice to drop the leading 0s.

1)      00001110

2)      11111100

3)      01001010

4)      10000011

5)      01101110

6)      11101010

7)      10101101

8)      1010000

9)      11111010

10)  11100010

11)  11011101

12)  11010101

13)  1001101

14)  1110

15)  11001010

16)  11100100

17)  101011

18)  1100101

19)  10000

20)  1011111

21)  11011

22)  100

23)  1000001

24)  11111

25)  10100110

1)      00001110 = 14

The number 00001110 represents: 8 + 4 + 2.

2)      11111100 = 252

The number 11111100  represents: 128 + 64 + 32 + 16 + 8 + 4.

3)      01001010 = 74

The number 01001010 represents: 64 + 8 + 2

4)      10000011 = 131

The number 10000011 represents: 128 + 2 + 1

5)      01101110 = 110

The number 01101110 represents: 64 + 32 + 8 + 4 + 2

6)      11101010 = 234

The number 11101010  represents: 128 + 64 + 32 + 8 + 2.

7)      10101101 = 173

The number 10101101 represents: 128 + 32 + 8 + 4 + 1

8)      1010000 = 80

The number 1010000 represents: 64 + 16

9)      11111010 = 250

The number 11111010 represents: 128 + 64 + 32 + 16 + 8 + 2

10)  11100010 = 226

The number 11100010 represents: 128 + 64 + 32 + 2

11)  11011101 = 221

The number 11011101 represents: 128 + 64 + 16 + 8 + 4 + 1

12)  11010101 = 213

The number 11010101 represents: 128 + 64 + 16 + 4 + 1

13)  1001101 = 77

The number 1001101 represents: 64 + 8 + 4 + 1

14)  1110 = 14

The number 1110 represents: 8 + 4 + 2

15)  11001010 = 202

The number 11001010 represents: 128 + 64 + 8 + 2

16)  11100100 = 228

The number 11100100 represents: 128 + 64 + 32 + 4

17)  101011 = 43

The number 101011 represents: 32 + 8 + 3 + 1

18)  1100101 = 101

The number 1100101 represents: 64 + 32 + 4 + 1

19)  10000 = 16

The number 10000 represents: 16

20)  1011111 = 95

The number 1011111 represents: 64 + 16 + 8 + 4 + 2 + 1

21)  11011= 27

The number 11011 represents: 16 + 8 + 2 + 1

22)  100 = 4

The number 100 represents: 4

23)  1000001 = 65

The number 1000001 represents:
64 + 1

24)  11111 = 31

The number 11111 represents: 16 + 8 + 4 + 2 + 1

25)  10100110 = 166

The number 10100110 represents: 128 + 32 + 4 + 2