Binary Arithmetic
Binary Arithmetic
Binary Arithmetic
Binary numbers can be manipulate in the same way as denary number.
Denary addition
369 + 733
Carry over 1 1 1
3 6 9
+ 7 3 3
1 1 0 2
12
1 + 0 =1 1 + 1 = 0 , carry 1 = 10
Carry over 1
1
1
+ 0 + 1
1
1 0
2 = 10 (binary number)
Place value 2 1
1 0
Binary Addition
The rule of binary addition
1 + 1 + 1 = 1 , carry 1 = 11
Carry over 1
1
1
+
1 In Binary addition, a carry over is used if the result is
greater than 1
1 1
3 = 11 (binary number)
21
1 1
3=2+1
3=11
Binary Addition
11010110 + 00100111 = ?
3 2
= =
11 10
Carry 1 1 1 1
1 1 0 1 0 1 1 0
0 1 1 0 0 1 1 1
1 0 0 1 1 1 1 0 1
All 8 bit have been used and the
3 2 carry over 1 has nowhere to go.
= =
11 10 Thus, the result of calculation is
wrong.
128 64 32 16 8 4 2 1
0 0 0 0 1 1 1 1 = 15
Exercise
1. Carry out the following binary additions
(a) 00011101 + 01100110
(b) 00100111+00111111
(c) 00101110 + 01001101
(d) 01110111 + 00111111
(e) 00011100 + 00110011
2. Convert the following denary numbers into binary number and then carry out the binary addition of two number
and check your answer against the equivalent sum:
(f) 29 + 88 (d) 51 + 171
(g) 49+100
(h) 82 + 69
Binary Shift
An operation done on all the bits of a binary value in which they are
moved by a specific number of places to either the left or right.
Binary shift can be used for multiplication and division by power of 2.
There are two type of binary shift.
Logical Shift
Arithmetic Shift
Logical Shift
Unsigned binary number multiplication by power of 2
Used left logical shift
Eg. 00010100 * 21
28 27 26 25 24 23 22 21 20
0 0 0 1 0 1 0 0 Number
0 0 1 0 1 0 0 0 Result
0
29 28 27 26 25 24 23 22 21 20
0 1 0 1 1 0 1 0 Number
010 1 1 0 1 0 0 0 0 Result
27 26 25 24 23 22 21 20
0 0 0 1 0 1 0 0
0 0 0 0 1 0 1 0
0
Number 0 0 0 1 0 1 1 0
Result 0 0 0 0 1 0 1
0
10
. 00010110 / 22 . = 00000101 =5
(incorrect
because the
rightmost 1 bit
is lost
Exercise
(1) What are the results of the following shifts on unsigned integers?
(a) 00111010 / 23
(b) 00011100 / 24
(c) 01101101 / 22
(d) 11101101 / 21
Two Complement
Use two complement.
Two complement is the method of representing binary to show they
are positive or negative.
Two’s Complement
Finding the two’s complement of a binary number
To find the two’s complement of a binary number
Flip all of the bits- change 1 to 0 and 0 to 1
Add 1 to the result.
Add 1 1
Add 1 to 1 1 1 0 0 1 0 0 = - 28
flip value
- 28 = 11100100
Two’s Complement
Find the binary number of – 69 using two complement
128 64 32 16 8 4 2 1
Number 0 1 0 0 0 1 0 1 = 69
Flip 1 0 1 1 1 0 1 0
Add 1 1
Add 1 to 1 0 1 1 1 0 1 1 = - 69
flip value
- 69 = 10111011
2) What is the two’s complement representation of the following denary
numbers?
a) -113
b) -56
Converting Two’s Complement Number Back
into Denary
Using place values, the two’s complement number can be converted directly into
denary.
Find the two’s complement binary number 11100100 into denary
- 128 64 32 16 8 4 2 1
1 1 1 0 0 1 0 0
-128 + 64 + 32 + 4 = -28
Converting Two’s Complement Number Back into Denary
- 128 64 32 16 8 4 2 1
1 0 1 1 1 0 1 1
-128 + 32 + 16 + 8 + 2 + 1 = -69
How to convert positive denary number into binary number using two’s
complement
- 128 64 32 16 8 4 2 1
0 0 1 0 0 1 1 1
Pg 22 Act 1.12
1. (a –c)
2. (a-c)
Pg 25 Act 1.13 (a-c)
Act 1.14(a-c)
Exercise
Convert the following negative denary numbers into binary numbers using two complements
(a) -47
(b) -88
(c) -100
(d) -127
(e) -63
Convert the following two’s complement representations of binary numbers into singed
denary number.
(f) 11001101
(g) 10111110
(h) 10000111
(i) 10100000
(j) 11000101
Adding Signed Integer
Find the binary addition of 28 -28 = 28+(-28)
1 1 1 1 1 1
Convert 28 to 8 bit binary number
0 0 0 1 1 1 0 0 =28
128 64 32 16 8 4 2 1 1 1 1 0 0 1 0 0 = -28
0 0 0 1 1 1 0 0 = 28
Convert - 28 to 8 bit binary number 1 0 0 0 0 0 0 0 0
Find the two complement of - 28
Number 0 0 0 1 1
1 0 0 = 28 There is an overflow
1 1 28 + (-28) = 00000000 = 0
Flip 1 1 1 0 0 0 1 1
Add 1 1
Add 1 to 1 1 1 0 0 1 0 0 = - 28
flip value
Adding Signed Integer
Find the binary addition of 5 + (-28)
1
Convert 5 to binary number
0 0 0 0 0 1 0 1=5
128 64 32 16 8 4 2 1 1 1 1 0 0 1 0 0 = -28
0 0 0 0 0 1 0 1 = 5
Convert - 28 to binary number 1 1 1 0 1 0 0 1 = - 23
Find the two complement of - 28 -128 64 32 16 8 4 2 1
Number 0 0 0 1 1 1 0 0 = 28
1 1
Flip 1 1 1 0 0 0 1 1
Add 1 1
5 + (-28) = 11101001 = -23
Add 1 to 1 1 1 0 0 1 0 0 = - 28
flip value
Exercise