DLD Lecture No. 5 Complement of Numbers 9 October 24
DLD Lecture No. 5 Complement of Numbers 9 October 24
Lecture No 5
Complement of Numbers
• 23456
• 5151
• 36547
• 9632541
Radix Complement (r’s Complement)
(2’s Complement)
• If we are given a number N in base-r having n digits the (r)’s
Complement or Radix Complement is defined as: rn - N
• Let N = 010101, n = 6 and r = 2,
So 2’s complement is 1’s complement +1 i.e. change 1 to 0 and 0 to 1
and then add 1 to the number.
So 2’s complement of 010101 is 101010+1 = 101011
2’s Complement
2’s Complement
Radix Complement (r’s Complement)
(2’s Complement)
• Find out 2’s Complement of following binary numbers:
• 10010
• 1010101
• 0001
• 10001
Diminished Radix Complement
((r-1)’s Complement) / 9’s Complement)
Diminished Radix Complement
((r-1)’s Complement) / 9’s Complement)
• If we are given a number N in base-r having n digits the (r-1)’s complement or
Diminished Radix complement is defined as (rn - 1) - N
• Example 1:
• Let us take r = 10 i.e. we need to find 9’s complement of a number. Let the
number be N, then 9’s complement of N is 10n -1 -N i.e. 999....99 (n digits) - N
• Example 2:
• Let us take N =1988. Here, r = 10 and n = 4, so 9’s complement of 1988 is 9999 -
1998 = 8001
• Example 3:
• Let us take N = 01234. Here, r = 10 and n = 5, so 9’s complement of 01234 is
99999 - 01234 = 98765
Diminished Radix Complement
((r-1)’s Complement) / 9’s Complement)
• 12345
• 456789
• 101456
• 98765
Diminished Radix Complement
((r-1)’s Complement) = 1’s Complement)
• 10101
• 111111
• 101
• 00001
Q&A