<<

What are binary numbers and why do we use them?

BINARY NUMBERS

Converting numbers to binary numbers The number system we commonly use is decimal numbers, also known as Base 10. Ones, tens, hundreds, and thousands.

For example, 4351 represents 4 thousands, 3 hundreds, 5 tens, and 1 ones.

Thousands Hundreds Tens ones 4 3 5 1 Thousands Hundreds Tens ones 4 3 5 1

However, a computer does not understand decimal numbers. It only understands “on and off,” “yes and no.” Thousands Hundreds Tens ones 4 3 5 1

In order to convey “yes and no” to a computer, we use the numbers one (“yes” or “on”) and zero (“no” or “off”). To break it down further, the number 4351 represents 1 times 1, 5 times 10, DECIMAL NUMBERS (BASE 10) 3 times 100, and 4 times 1000.

Each step to the left is another multiplication of 10. This is why it is called Base 10, or decimal numbers. The prefix dec- 4351 means ten.

4x1000 3x100 5x10 1x1 One is 10 to the zero power. Anything raised to the zero power is one. DECIMAL NUMBERS (BASE 10) Ten is 10 to the first power (or 10). One hundred is 10 to the second power (or 10 times 10).

One thousand is 10 to the third 4351 power (or 10 times 10 times 10).

4x1000 3x100 5x10 1x1

103=1000 102=100 101=10 100=1 Binary numbers, or Base 2, use the number 2 instead of the number 10. 103 102 101 100 The prefix bi- means two. Base 10 1000 100 10 1 Base 23 22 21 20 2 8 4 2 1 Two raised to the zero power is one. Two raised to the first power is two. Two raised to the second power is four (or 2 times 2). Two raised to the third power is eight 3 2 1 0 (or 2 times 2 times 2). Base 10 10 10 10 10 1000 100 10 1 Base 23 22 21 20 2 8 4 2 1 And so on… Eight times two is sixteen, or two to the BINARY NUMBERS (BASE 2) .

Sixteen times two is thirty-two, or two to the . Base 23 22 21 20 2 8 4 2 1 27 26 25 24 128 64 32 16 Thirty-two times two is sixty-four, or two to BINARY NUMBERS (BASE 2) the sixth power.

And sixty-four times two is one hundred twenty eight, or two 3 2 1 0 to the . Base 2 2 2 2 2 8 4 2 1 27 26 25 24 128 64 32 16 The number fifteen is written in decimal as one ten and five ones. In binary, the number fifteen is written as one eight, one four, DECIMAL one two, and one one. BINARY These are called , and they are either one (on) or zero (off). 15 15

1 5 1 1 1 1

101=10 100=1 23=8 22=4 21=2 20=1

15 1111 Eight bits make a .

8 BITS = 1 BYTE = 1 OCTET This is also known as an octet.

When you see an IP address, it is 27 26 25 24 23 22 21 20 made up of four octets (or 32 bits). 128 64 32 16 8 4 2 1 8 BITS = 1 BYTE = 1 OCTET If every is a zero…that’s eight zeros… 27 26 25 24 23 22 21 20 and we multiply each by zero, 128 64 32 16 8 4 2 1 and add them up… x x x x x x x x the decimal equivalent of that octet is zero. 0 0 0 0 0 0 0 0 ======0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 = 0 8 BITS = 1 BYTE = 1 OCTET If every bit is a one…that’s eight ones… and we multiply each power of two by one, and add them up… 27 26 25 24 23 22 21 20 the decimal equivalent is two hundred and 128 64 32 16 8 4 2 1 fifty-five. x x x x x x x x Therefore, each octet can have a value 0 0 0 0 0 0 0 0 between 0 and 255. ======0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 = 0 x x x x x x x x 1 1 1 1 1 1 1 1 ======128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255 Let’s look at an IP address.

It is easier for us to recognize decimal numbers, so we write the IP address as 192.168.131.106.

However, a computer sees the IP address in binary notation as four octets of ones and zeros.

Decimal notation → 192 . 168 . 131 . 106

Binary notation → 11000000 . 10101000 . 10000011 . 01101001 Binary notation → 11000000 . 10101000 . 10000011 . 01101001

27 26 25 24 23 22 21 20

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

To convert binary numbers to decimal numbers, we use the powers of two again.

Write the octet below…one in the 128 column, one in the sixty-four column, and zeros for the rest. Binary notation → 11000000 . 10101000 . 10000011 . 01101001

128 64 32 16 8 4 2 1

1 1 0 0 0 0 0 0

128 + 64 + 0 + 0 + 0 + 0 + 0 + 0 = 196

Then multiply each column and add across…128 plus 64 plus zero equals 196. Decimal notation → 196 Binary notation → 11000000 . 10101000 . 10000011 . 01101001

128 64 32 16 8 4 2 1

1 0 1 0 1 0 0 0

128 + 0 + 32 + 0 + 8 + 0 + 0 + 0 = 168

Write the second octet, multiply down and add across. 128 plus 0 plus 32 plus 8 plus 0 equals 168. Decimal notation → 192 . 168 . 131 Binary notation → 11000000 . 10101000 .

131 128 64 32 16 8 4 2 1 -128 1 3

Now we’ll convert the other way…from decimal to binary…for the third and fourth octets. To convert 131 to binary…we start from the left.

Can we subtract 128 from 131? Yes. So we put a one in the 128 column, and we are left with three. Decimal notation → 192 . 168 . 131 Binary notation → 11000000 . 10101000 .

131 128 64 32 16 8 4 2 1 -128 1 0 0 0 0 0 3

Can we subtract 64 from 3? No. So we put a zero in the 64 column.

Can we subtract 32 from 3? No. Another zero for the 32 column.

Zero in the 16 column, the 8 column, and the four column. Decimal notation → 192 . 168 . 131 Binary notation → 11000000 . 10101000 . 10000011 .

131 128 64 32 16 8 4 2 1 -128 1 0 0 0 0 0 1 1 3 -2 1 Can we subtract a 2 from 3? Yes, and -1 we put a one in the two column. We are left with one in the one column. 0

So 131 in binary is 10000011. Decimal notation → 192 . 168 . 131 . 106 Binary notation → 11000000 . 10101000 . 10000011 .

106 128 64 32 16 8 4 2 1 -64 0 1 1 42 -32 10

Now we’ll convert the fourth octets. Starting from the left.

Can we subtract 128 from 106? No. Can we subtract 64 from 106? Yes, and we are left with 42. Can we subtract 32 from 42? Yes, leaving 10. Decimal notation → 192 . 168 . 131 . 106 Binary notation → 11000000 . 10101000 . 10000011 . 01101010

106 128 64 32 16 8 4 2 1 -64 0 1 1 0 1 0 1 0 42 -32 10 Can we subtract 16 from 10? No. -8 Can we subtract 8 from 10? Yes, leaving 2. 2 Can we subtract 4 from 2? No. Can we subtract a 2 from 2? Yes, leaving 0.

So, 106 written in binary is 01101010. I hope this has helped you understand a little bit about converting binary numbers.

Thanks for watching!

North Campus Learning Lab Room NA-113i