Professional Documents
Culture Documents
Lecture # 4
Subtraction using 1’s & 2’s compliment
• A – B = A + (-B)
– Perform Y-X
Case 2
• Using 2’s Complement of following signed
numbers:
– Perform +6+13 ,
– Perform +6-13
– Perform -6-13
Binary Code
A = 0110 6
B = 1000 8
S = 1110 14 Invalid BCD
Add 6 for correction
S = 1110
6 = 0110
Ans = 10100
0001 0100
1 4
BCD Addition
• Case 3 : Sum equals to 9 or less with carry 1
– Add 6 bits for correction
– E.g : 8 + 9 = 17
A = 1000 8
B = 1001 9
S= 10001
0001 0001 11 Invalid Result
Add 6 for correction
S = 0001 0001
6 = 0110
Ans = 0001 0111
1 7 Correct Result
Self Task
• Add 24 + 18 = 42
A = 0010 0100 24
B = 0001 1000 18
S = 0011 1100 312 Invalid
Add 6 = 0110
= 0100 0010
4 2 Correct Result
Gray Code 0000 0
0001 1
0011 2
• Use to detect errors in 0010 3
the bits 0110
0111
4
5
• Two numbers differ only 0101 6
0100 7
in 1 bit position 1100 8
• 0-15 decimal 1101 9
1111 10
1110 11
1010 12
1011 13
1001 14
1000 15
Conversions
• Gray code to binary code (Discard Carries)
G =1 1 1 0
B =1 0 1 1
Conversions
• Binary code to Gray code (Add)
• B = 1 0 1 1 (Discard Carries)
• G = 1 1 1 0
Self Task