Title: Binary Arithmetic
1Binary Arithmetic
2Addition
- Add 2 digits ? sum carry
- 7 5
- 2 7
- ------ ------
- 0 9 1 2
- carry sum
carry sum
3Binary Addition
- Adding Binary Digits
- a b sum a b carry
- ------------------ -----------------
- 0 0 0 0 0 0
- 0 1 1 0 1 0
- 1 0 1 1 0 0
- 1 1 0 1 1 1
- Sum Digit1 XOR Digit2
- Carry Digit1 AND Digit2
4Binary Addition
Half Adder
Full Adder
Multiple bit adder
5Example
- Decimal Addition
- 5 6 11
- Binary Addition
- 00101 5
- 00110 6
- --------------
- 01011 11
-
6Binary Subtraction
- Decimal Subtraction
- 20 3 20 (-3)
- Binary Subtraction
- 20 100100
- -3 ? Twos Complement of Binary
representation of 3
7Twos Complement
- Ones Complement
- Convert 0 to 1, and 1 to 0
- What is Ones complement of 00011001?
- It is 11100110
- Twos Complement
- Add 1 to the ones complement
- What is the Twos complement of 00011001?
- It is 11100111
8Twos Complement
- (-1) (1111)
- (-2) (1110)
- (-3) (1101)
- .
- .
9- In a n bits register ? unsigned numbers in the
range of . - In a n bits register ? signed numbers in the
range of .
10Binary Subtraction
- Decimal Subtraction
- 20 3 20 (-3) 17
- Binary Subtraction
- 20 10100
- (-3) 01101
- -------------------------
- 10001 17
11Unsigned Binary Addition Example
4 bit numbers can represent numbers from 0 to 15
The result 18 is not in the range 0,15, And is
too big. Consequently, Overflow happens here. So
the carry bit from adding the two most
significant bits represents a results that
overflows.
12Signed Binary Addition Example
signed 4 bit numbers (2's complement) can
represent numbers between -8 and 7
The extra carry from the most significant bit has
no meaning
13Signed Binary Addition Example
signed 4 bit numbers (2's complement) can
represent numbers between -8 and 7
if two numbers with the same sign (either
positive or negative) are added and the result
has the opposite sign, an overflow has occurred.
14Midterm Examples
- 3. Do the following signed binary arithmetic.
Use 2's complement when appropriate. V bit is
Overflow and C bit is Carry - a) X 7, Y 2, Z X Y
- b) X 7, Y 2, Z X - Y
- c) X 2, Y 7, Z X - Y