Binary Numbers
Binary Numbers
You set the unit number back to zero and add a 1 in the
tens place. When you get to 19, you set the unit number
back to zero and change the tens digit to 2. Similarly
when you get to 99, you must change the units and the
tens to 0. Then, you add a one in the hundreds place to
get 100.
Or,
3 x 1000 + 4 x 100 + 2 x 10 + 7 x 1
But
1000 = 10 x 10 x 10 = 103
100 = 10 x 10 = 102
10 = 101
1 = 100
(You can check this on your calculator)
So,
3427 = 3 x 103 + 4 x 102 + 2 x 101 + 7 x 100
1
The Binary System
The binary system has only 2 digits: 0 and 1. In binary,
the first digit is 0 and the second digit is 1. But what
happens next? Well in the decimal system, when you get
to 9, you put a 0 in the units place and a one in the tens
place. Similarly, when you get to 1 in binary the next
number is 10. The next number is then 11. What do you
think comes next?
2n Total
20 1
21 2
22
23
24
25
26
27
28
29
2
Converting from Binary to Decimal
Remember that:
Similarly,
1111 = 1 x 23 + 1 x 22 + 1 x 21 + 1 x 20
=1x8+1x4+1x2+1x1
=8+4+2+1
=15
And:
100110 = 1 x 25 + 0 x 24 + 0 x 23 + 1 x 22 + 1 x 21 + 0
x 24
= 32 + 4 + 2
= 38
Exercise
Convert the following binary numbers to decimal form.
(i) 1102
(ii) 110012
(iii) 1010112
(iv) 11102
(v) 110112
(vi) 10000012
(vii) 11100112
(viii) 101112
(ix) 10010102
(x) 110011002
3
Converting from Decimal to Binary
Converting from decimal to binary involves repeatedly
dividing by 2 until you get 0.
Example
Convert 15610 to binary.
2|156 Remainder
2|78 0
2|39 0
2|19 1
2|9 1
2|4 1
2|2 0
2|1 0
1 Binary number: 100111002
Exercise
Convert the following decimal numbers to binary form.
(i) 12
(ii) 62
(iii) 128
(iv) 248
(v) 572
(vi) 891
(vii) 945
(viii) 1202
(ix) 1668
(x) 14772
4
Adding Decimals
To add a decimal, you write one number on top of the
other number. Then, you add the numbers in each
column staring on the right.
Example
Add the numbers 32 and 49.
320
493
3
3 20
4193
13
3 20
4193
713
Example
Add 1112 and 1002
111
100
5
First, add the rightmost column: 1 + 0 = 1, which is a
binary number.
111
100
1
111
100
11
111
100
1011
1112 = 1 x 22 + 1 x 21 + 1 x 20 = 7
1002 = 1 x 22 + 0 x 21 + 0 x 20 = 4
7 + 4 = 11
10112 = 1 x 23 + 0 x 22 + 1 x 21 + 1 x 20 = 11
Therefore,
111
100
1011 Q.E.D.
Exercise
Add the following binary numbers
(i) 11 + 101
(ii) 101 + 100
6
(iii) 1110 + 1010
(iv) 1000 + 101
(v) 10010 + 1100
(vi) 1011101 + 1000000
(vii) 10011 + 1111101
(viii) 10011001 + 100111
(ix) 11000011 + 10111
(x) 100110 + 1100101
Ones Complement
1s complement is calculated by changing all the 1s in a
binary number to 0 and converting all the 0s to 1.
Example
Find the 1s complement of the following numbers.
(i) 001
(ii) 010
(iii) 000
(iv) 0101
(v) 0011
(vi) 0111
(vii) 01110100
(viii) 00001111
(ix) 01010000
(x) 00101010
Example
Let’s find -310 in binary.
7
Therefore, -310 = 100 (just change all the 0s to 1s and
1s to 0s).
Exercise
Using 8-bit format, convert all the following decimal
numbers to binary form.
(i) -2
(ii) -1
(iii) -6
(iv) -7
(v) -11
(vi) -12
(vii) -15
(viii) -18
(ix) -20
(x) -25
Twos Complement
Two complement is used by computers to represent
negative numbers. To get the two's complement
negative notation of an integer, you write out the
number in binary. You then invert the digits, and add
one to the result.
Example
Find the twos complement of the following 8-bit number.
00010001
11101110 + 1 = 11101111
8
Exercise
Find the twos complement of the following numbers.
(i) 001
(ii) 010
(iii) 011
(iv) 0101
(v) 0010
(vi) 0111
(vii) 01110100
(viii) 00001111
(ix) 01010000
(x) 00101010
Negative Numbers
Suppose we’re working in 8-bit format and want to
change the integer -28 to binary. First write 28 in 8-bit
binary form.
2810 = 00011100
= 11100011 + 1 = 11100100
Exercise
(i) -3
(ii) -4
(iii) -5
(iv) -9
(v) -10
(vi) -11
(vii) -14
(viii) -16
(ix) -21
(x) -22
9
Binary Addition Reviewed
Let’s look at binary addition again.
Example
Add the decimal numbers 68 and 11 in binary form.
6810 = 01000100
1110 = 00001011
01000100
+00001011
01001111
And 010011112
= 2 7 x 0 + 26 x 1 + 2 5 x 0 + 24 x 0 + 23 x 1 + 2 2 x 1 +
2 1 x 1 + 20 x 1
= 0 + 64 + 0 + 0 + 8 + 4 + 2 + 1
= 79
Exercise
Add the following decimal numbers in binary form.
Check your answer by converting back to decimal form.
(i) 3 + 12
(ii) 7+9
(iii) 8 + 11
(iv) 14 + 17
(v) 15 + 19
(vi) 20 + 8
(vii) 22 + 15
(viii) 23 + 16
(ix) 24 + 10
(x) 30 + 11
10
Binary Subtraction
What happens if you want to subtract? Let’s look at 68 –
11.
01000100
-00001011
Example
11 = 00001011
-11 = 11110101
68 + (-11) =
01000100
11110101
100111001
68 – 11 = 57
001110012 = 27 x 0 + 26 x 0 + 25 x 1 + 24 x 1 + 23 x 1
+ 2 2 x 0 + 21 x 0 + 2 0 x 1
= 0 + 0 + 32 + 16 + 8 + 0 + 0 + 1
= 57
Exercise
Add the following decimal numbers in binary form.
Check your answer by converting back to decimal form.
(i) 12 - 3
11
(ii) 8-2
(iii) 9-5
(iv) 17 - 11
(v) 15 - 4
(vi) 19 - 12
(vii) 16 - 8
(viii) 25 - 15
(ix) 43 - 20
(x) 52 – 18
Example
10011001 = 01100110 + 1 = 01100111
Exercise
Convert these numbers from twos complement.
(i) 11001001
(ii) 11100000
(iii) 10111111
(iv) 10000110
(v) 11000000
Example
01000100 - this is a positive number.
12
Exercise
Are the following numbers negative or positive?
(i) 11000111 –
(ii) 01110100 –
(iii) 10111100 –
(iv) 00000111 –
(v) 01100110 –
13