Professional Documents
Culture Documents
Dr. M. edit Master subtitle style Click toNajam ul Islam PhD Electrical Engineering
Lecture 3: Ns Complement
22
Magnitude
44
Complements
In base-10:
In base-2
55
10s Complement
Given a positive number N in base n with an integer
part of r digits, then ns complement is defined as n - N 10s complement of (52520) is 10 - 52520 = 100000 52520 = 47480 Similarly, 10s complement of 134795 is 865205
66
10s Complement
10s complement of (0.3267) = 10 0.3267
= 1 - 0.3267 = 0.6733
77
2s Complement
2s Complement of (101100) is
(2) (101100) = (1000000 101100) = 010100 2s Complement of (0.0110)2 is (20) (0.0110) = (1.0000 0.0110) = 0.1010 Rules for binary Subtraction 0-0=0 0 - 1 = 1, and borrow 1 from the next more significant bit 1-0=1 1-1=0 (26)10 = (64)10 = (1000000)2 (20)10 = (1)10 = (1)2
88
For an n bit number N the 2s complement is (2n 1) N + 1. Called radix complement by Mano since 2s complement for
base (radix 2). To find negative of number (represented in 2s complement), take the 2s complement.
Sign bit 99
Sign bit
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
1010
(n-1)s Complements
Given a positive number N in base n with an integer
part of r digits and a fraction part of m digits then (n1)s complement is defined as n- n-m - N
Need to accommodate the fraction part through n-m 9s complement of (52520) is (10 10 52520) = 100000 1 52520 = 47479
Remember the rule: Ns complement is +1 unit (add 1) to the (N1)s complement.
1111
9s Complement
9s complement of (0.3267) is (10 10 0.3267) = 0.9999 0.3267 = 0.6732 9s complement of (25.639) is (10 10 25.639) = 99.999 25.639 = 74.360 Find the 9s and 10s complements of 314700. 9s complement = 685299 10s complement = 685300 zeros unchanged. Then subtract the first non-zero digit from 10 and all the remaining digits from 9s.
A version of Algorithm 2 on Slide 6, for binary numbers
1212
1s Complement
1s complement of 110100101 is 001011010
which can be obtained by replacing each one by a zero and each zero by one.
Sign bit
1515
1616
1s Complement Addition
Using 1s complement numbers, adding numbers is easy. For example, suppose we wish to add +(1100)2 and +(0001)2. Lets compute (12)10 + (1)10. (12)10 = +(1100)2 = 011002 in 1s comp. (1)10 = +(0001)2 = 000012 in 1s comp.
0 1 1 0 0 + 0 0 0 0 1 Ad -------------d 0 0 1 1 0 1 0 Add carry -------------0 1 1 0 1 Final
Resu lt
1717
2s Complement Addition
Using 2s complement numbers, adding numbers is easy. For example, suppose we wish to add +(1100)2 and
+(0001)2. Lets compute (12)10 + (1)10. (12)10 = +(1100)2 = 011002 in 2s comp. (1)10 = +(0001)2 = 000012 in 2s comp.
Ad d Final Res ult
0 1 1 0 0 + 0 0 0 0 1 -------------0 0 1 1 0 1
1818
Igno re
Exercise
Find the 1s and 2s complements of the binary number
1101001101
1919
1. Add the minuend M to the ns complement of the 1. Inspect the result obtained above for an end carry:
a) If an end carry occurs, discard it and write the answer as it is b) If an end carry does not occur, then take ns complement of the
number obtained in step 1, and place a negative sign in front.
2020
2s Complement Subtraction
Using 2s complement numbers, follow steps for subtraction For example, suppose we wish to subtract +(0001)2 from +(1100)2. Lets compute (12)10 - (1)10.
(12)10 = + (1100)2 = 011002 in 2s comp. (-1)10 = - (0001)2 = 111112 in 2s comp.
0 1 1 0 0 0 0 0 0 1 --------------
Step 1: Take 2s complement of 2nd operand Step 2: Add binary numbers Step 3: Ignore carry bit
2121
2222
2323
Exercise
Using 10s complement subtract 3250 from 72532
M = 72532 N = 03250
2424
Exercise
Subtract (3250 72532) using 10s Complement.
M = 03250 N = 72532
2525
Exercise
Using 2s complement subtract 1000100 from 1010100
M = 1010100 N = 1000100
2s complement of N = 0111100
1010100 + 0111100 = 10010000 Answer = 10000
2626
Exercise
Subtract (1000100 1010100) using 2s Complement
M = 1000100 N = 1010100
2s complement of N = 0101100
1000100 + 0101100 = 01110000
2727
1. Add the minuend M to the (n-1)s complement of the 1. Inspect the result obtained above for an end carry:
a) If an end carry occurs, add 1 to the number. b) If an end carry does not occur, then take (n-1)s complement of
the number obtained in step 1, and place a negative sign in front.
2828
1s Complement Subtraction
Using 1s complement numbers, subtracting numbers is also easy. For example, suppose we wish to subtract +(0001)2 from +(1100)2. Lets compute (12)10 - (1)10. 0 1 1 0 0 (12)10 = +(1100)2 = 011002 in 1s comp. - 0 0 0 0 1 (-1)10 = -(0001)2 = 111102 in 1s comp. -------------1s comp Ad d
Step 1: Take 1s complement of 2nd operand Step 2: Add binary numbers Step 3: Add carry to low order bit Add carry Final Res ult
2929
0 1 1 0 0 + 1 1 1 1 0 -------------1 0 1 0 1 0 1 -------------0 1 0 1 1
Exercise
Using 9s complement subtract 3250 from 72532
M = 72532 N = 03250
9s complement of N = 96749
72532 + 96749 = 169281 Add this end carry to the above i.e. 69281 +1 Answer = 69282
3030
Exercise
Subtract (3250 72532) using 9s Complement.
M = 03250 N = 72532
3131
Exercise
Using 1s complement subtract 1000100 from 1010100
M = 1010100 N = 1000100
1s complement of N = 0111011
1010100 + 0111011 = 10001111 Add this end carry to the above i.e. 0001111 + 1 Answer = 10000
3232
Exercise
Subtract (1000100 1010100) using 1s Complement
M = 1000100 N = 1010100
1s complement of N = 0101011
1000100 + 0101011 = 01101111
3333
Sample Quiz
Convert the following into Binary, Hexadecimal & Octal.
53.0286 106.274
3434