Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 13

Binary

Arithmetic
Lecture 6
Objectives
Binary addition
Binary subtracion
Binary addition
In the same way as adding two decimal numbers to a
number to obtain a result and a carry to carry back, to
add two binary numbers, it is necessary to define the
addition of 2 bits. There are only four cases to consider:
0 + 0 gives 0 result and 0 carry.
0 + 1 gives 1 result and 0 carry.
1 + 0 gives 1 result and 0 carry.
1 + 1 gives 0 result and 1 carry (just as there is a hold
on adding two decimal digits when the result is greater
than 10).
Addition (binary)

1
0 1 0 1
0 0 1 1
0 1 1 10
Addition (binary)

1 11 1
011 01
01011
11000
Examples
Exercise
Add 14 and 17
Add 34 and 10
Binary Subtraction with
twos complement
Steps for subtracting x from y with an n-bit 2's
complement representation:
1)Negate x using 2's complement.
a) Reverse all the bits in x.
b) Add 1 to form -x.

2)Add -x and y.
3)Discard any bits greater than n.
Calculating twos
complement
The twos complement of a binary integer is the 1s
complement of the number plus 1.
Thus if m is the 2s complement of n, then: m = n + 1
Examples:
n = 0101 0100, then m = 1010 1011 + 1 = 1010 1100
n = 0101 1111, then m = 1010 0000 + 1 = 1010 0001
n = 0111 1111, then m = 1000 0000 + 1 = 1000 0001
n = 0000 0001, then m = 1111 1110 + 1 = 1111 1111
Binary Subtraction -
Examples
80 0101 0000 0101 0000
65 0100 0001 1011 1111
65 1011 1110 1 1 0000 1111

Discard Carry Bit from Result
Binary Subtraction -
Examples
Consider 8110 - 4510 using 2's
complement and 8 bits
10100012 - 001011012
2's complement of 4510 = 110100112
001010001 + 11010011 = 100100100
End carry occurs
Discard end carry
Difference = 001001002 = 3610
Binary Subtraction -
Examples
Consider 5310 - 6010 using 2's
complement and 8 bits
001101012 - 001111002
2's complement of 6010 = 110001002
00110101 + 11000100 = 11111001
No end carry
Result (111110012) is in 2's complement notation
Difference = 111110012 = -710
Exercise
64-21
45-23

You might also like