Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 32

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

In denary addition, a carry over is used if the result is


greater than 9
Binary Addition
 The rule of binary addition

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 = ?

Place value 128 64 32 16 8 4 2 1


Carry 1 1
Number 1 1 0 1 0 1 1 0 214
Number 0 0 1 0 0 1 1 1
39
Total 1 1 1 1 1 1 0 1 253

3 2
= =
11 10

11010110 + 00100111 = 11111101


Binary Addition
11010110 + 01100111 = ?

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.

 This is called overflow.


11010110 + 01100111 = 00111101
11010110 + 01100111 = 1 00111101
Binary Addition
Overflow error
 This condition occurs when a calculation produces a result that is
greater than the computer can store.
 When this happens, the microprocessor/processor is informed that an
error has occurred.
Exercise
1) Carry out the following binary additions.
a) 00001101 + 10101010
b) 11010111 + 10001010
c) 00101010 + 10001011
Example (Addition)
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:
98 + 15

Convert 98 to 8 bit binary number 1 1 1


0 1 1 0 0 0 1 0 = 98
128 64 32 16 8 4 2 1 0 0 0 0 1 1 1 1 = 15
0 1 1 0 0 0 1 0 = 98
0 1 1 1 0 0 0 1 = 113
Convert 15 to 8 bit binary number
128 64 32 16 8 4 2 1

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

The binary should be one shift to the left

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

. 00010100 * 21. = 00101000


Logical Shift
 Eg. 01011010 * 23

The binary should be three shift to the left

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

. 01011010 * 23 . = 11010000 (incorrect answer because the


leftmost 1 bit is lost)
Exercise
(1) What are the results of the following shifts on unsigned integers?
(a) 00111010 * 23
(b) 00011101 * 24
(c) 00101101 * 22
(d) 01101101 *21
Logical Shift
 Unsigned binary number division by power of 2
 Used Right logical shift
 Eg. 00010100 / 21

The binary should be one shift to the Right

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

. 00010100 / 21. = 00001010


Logical Shift
 Eg. 00010110 / 22

The binary should be two shift to the Right

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

Page 20. Activity 1.11


Conversion of signed/negative denary to binary number

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.

Convert - 28 to binary number using two ‘s complement


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

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

Most significant bit (MSB) represents a


negative number rather than sign.
The MSB 1 indicating a negative number

-128 + 64 + 32 + 4 = -28
Converting Two’s Complement Number Back into Denary

Find the two’s complement binary number 10111011 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

Find the denary number of 39 using two 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

 Find the binary addition of 70+ (-35)


Exercise
(1) Show your working, carry out the binary addition of 90 + (-33)
(2) What are the results of the following shifts on unsigned integers?
(a) 00111010 * 23 (b) 10011101 / 24
Logical Shift
 Used for unsigned binary number multiplication and division by power of
2.
 In left logical shift, the left most bits drop off the end and are replaced by
0’s at the right.
 In right logical shift, the right most bits drop off the end and are replaced
by 0’s at the left.
Calculate the product of the following expression in binary form
(a) -72 * 21
(b) -12 * 22
(c) -5 * 23
Exercise
Shows the following divisions using Arithmetic shift
(a) 11011010 / 21
(b) 10111011/ 22

You might also like