1. Binary Arithmetic
โข Adding Binary numbers
โข Overflow conditions
โข How does it all work?
โข AND, OR and NOT
2. Decimal Addition
โข You are probably already familiar with adding
decimal numbers
7
+2
9
5
+1
6
2
+3
5
โข You also know that when the addition of two
numbers exceeds the base, a value is โcarriedโ over
to the next column
7
+ 5
1 2
1 Carry the โ1โ
3. Binary Addition
โข Adding binary numbers employs the same
procedures as adding decimal numbers:
00
+00
00
01
+00
01
00
+01
01
โข As with decimal addition, when the addition of two
numbers exceeds the base value, the value is
โcarriedโ over to the next column
01
+01
10
1 Carry the โ1โ
5. More Binary Addition Examples
01111111
01000001
11000000
10001100
00111011
11000111
01111111
01001001
11001000
11111111
00000001
????????
โข What happens when we get the following case?
(note: assume that we are limited to 8 bits)
6. Overflow
11111111
00000001
00000000
โข In the following case, we have a condition called
โoverflowโ. The result may be somewhat unexpected
1 Carry the โ1โ
โข When adding two numbers, it is possible that the
result will not fit within the space we have provided.
The addition completes, but part of the value is lost.
โข Luckily, overflow is often considered to be an error
condition, so the program โknowsโ that this has
happened and can take appropriate action.
7. How does it all work?
โข In the first week of lectures, we discussed vacuum
tubes, relays, and transistors
โข As we went through the discussion, I asked, โHow
could you add two numbers using switches?โ
โข I didnโt expect an answer, but I did show how switches
could be set up to implement the AND function and the
OR function.
8. AND, OR and NOT
โข You may recall the โtruthโ tables for the AND and OR
functions:
0 1
0 0 0
1 0 1
0 1
0 0 1
1 1 1
A
B
A
B
AND OR
โข The AND, OR and NOT functions are the basic
functions for โBooleanโ Algebra
0 1
1 0
A
NOT (~)
9. Binary Arithmetic/AND and OR
โข All binary arithmetic can be represented using
boolean algebra
โข Each 1-bit adder has 3 inputs: A, B and CarryIn
โข Each 1-bit adder has 2 output: C and CarryOut
CIN 0 0 0 0 1 1 1 1
A 0 0 1 1 0 0 1 1
B 0 1 0 1 0 1 0 1
C 0 1 1 0 1 0 0 1
COUT 0 0 0 1 0 1 1 1
10. Boolean Equations for Addition
CIN 0 0 0 0 1 1 1 1
A 0 0 1 1 0 0 1 1
B 0 1 0 1 0 1 0 1
C 0 1 1 0 1 0 0 1
COUT 0 0 0 1 0 1 1 1
C = (~A and B and ~CIN) or (A and ~B and ~CIN) or
(~A and ~B and CIN) or (A and B and CIN)
COUT= (A and B) or (A and CIN) or (B and CIN)