Complements
Complements
Lecture 3
Take the first bit as a sign indicator, thus leaving the 7 last bits
to represent the numbers.
10011010 01100100
+ 1 + 1
--------------- ---------------
10011011 01100101
° Algorithm 2 – Starting with the least significant bit, copy all
of the bits up to and including the first 1 bit and then
complementing the remaining bits.
• N =01100101
[N] =10011011
1’s Complement
Addition
° Using 1’s complement numbers, adding numbers
is easy.
° For example, suppose we wish to add +(1100)2
and +(0001)2.
° Let’s compute (12)10 + (1)10.
• (12)10 = +(1100)2 = 011002 in 1’s comp.
• (1)10 = +(0001)2 = 000012 in 1’s comp. 0 1 1 0 0
Add + 0 0 0 0 1
Step 1: Add binary numbers --------------
Step 2: Add carry to low-order bit 0 0 1 1 0 1
Add carry 0
--------------
Final
Result
0 1 1 0 1
1’s Complement
Subtraction
° Using 1’s complement numbers, subtracting
numbers is also easy.
° For example, suppose we wish to subtract
+(0001)2 from +(1100)2.
0 1 1 0 0
° Let’s compute (12)10 - (1)10. - 0 0 0 0 1
• (12)10 = +(1100)2 = 011002 in 1’s comp. --------------
• (-1)10 = -(0001)2 = 111102 in 1’s comp.
1’s comp
0 1 1 0 0
Step 1: Take 1’s complement of 2nd operand Add + 1 1 1 1 0
Step 2: Add binary numbers
Step 3: Add carry to low order bit
--------------
1 0 1 0 1 0
Add carry 1
Final
--------------
Result 0 1 0 1 1
2’s Complement
Addition
° Using 2’s complement numbers, adding numbers
is easy.
° For example, suppose we wish to add +(1100)2
and +(0001)2.
° Let’s compute (12)10 + (1)10.
• (12)10 = +(1100)2 = 011002 in 2’s comp.
• (1)10 = +(0001)2 = 000012 in 2’s comp. 0 1 1 0 0
Add + 0 0 0 0 1
Step 1: Add binary numbers --------------
Step 2: Ignore carry bit Final 0 0 1 1 0 1
Result
Ignore
2’s Complement
Subtraction
° Using 2’s complement numbers, follow steps for
subtraction
° For example, suppose we wish to subtract
+(0001)2 from +(1100)2.
0 1 1 0 0
° Let’s compute (12)10 - (1)10. - 0 0 0 0 1
• (12)10 = +(1100)2 = 011002 in 2’s comp. --------------
• (-1)10 = -(0001)2 = 111112 in 2’s comp.
2’s comp
0 1 1 0 0
Step 1: Take 2’s complement of 2nd operand Add + 1 1 1 1 1
Step 2: Add binary numbers
Step 3: Ignore carry bit
--------------
Final
Result 1 0 1 0 1 1
Ignore
Carry
2’s Complement Subtraction: Example
#2
Alphabetic codes
Numeric codes
Punctuation, etc.
To detect and correct the errors, additional bits are added
to the data bits at the time of transmission.
The data bits along with the parity bits form a code word.
° Even parity -- Even parity means the number of 1's in the
given word including the parity bit should be even
(2,4,6,....).
° Odd parity -- Odd parity means the number of 1's in the
given word including the parity bit should be odd (1,3,5,....).
Pari
ty
°Cod
esParity codes are formed by concatenating a parity
bit, P to each code word of C.
° In an odd-parity code, the parity bit is specified so
that the total number of ones is odd.
° In an even-parity code, the parity bit is specified
so that the total number of ones is even.
P Information Bits
1 1 0 0 0 0 1 1 0 1 0 0 0 0 1 1
Added even parity bit Added odd parity bit
Pari
ty
°Cod
e Concatenate a parity bit to the ASCII code for the
characters 0, X, and = to produce both odd-parity
Exa
and even-parity codes.
mpl
e
Character ASCII Odd-Parity Even-Parity
ASCII ASCII
0 0 1 0 1 0 1 1
Binary Cell
Register Transfer
Register A Register B
Digital Logic
Circuits
Register C
Transfer of
Information