You are on page 1of 18

Discrete

Mathematics

Number Theory #2
Outlines
 Signed Numbers
 Divisibility & Modular Arithmetic
Complements:-
There are two types of complements for each base r system. The first is r’s (radix
complement), and the second is (r-1)’s (diminished radix complement) complement.
Thus, for the binary system, we have 2’s complements, and 1’s complement since the binary number
system is of base 2. For the decimal number system, we would have 10’s complement, and 9’s
complement since the decimal number system is of base 10.

1) (r-1)’s complement:-
Given a number N in base r having n digits, the (r-1)’s complement of N is defined as (rn- 1)- N.
For example, what is the 9’s complement of 546700? In here,
N = 546700
r = 10
n = 6 digits.

Thus, the 9’s complement of (546700) is ((rn-1)- N) which is

(106-1)-546700 = (1,000,000 –1) – 546700 = 999,999 – 546700


= 453,299
For the binary numbers, since the base is 2, (2-1)’s complements or 1’s complements is
defined as (2n-1)-N.
For example, what is the 1’s complement of (1011000)?
N = 1011000
r=2
n=7
Thus the 1’s complement of (1011000) is ((rn-1)- N) which is

(27-1)-1011000 = (10000000 - 1) – 1011000 = 1111111 – 1011000 = 0100111

Lets take another example, what is the 1’s complement of (1001)?


N = 1001
r=2
n= 4
Thus the 1’s complement of (1001) is ((rn-1)- N) which is

(24-1)-1001 = (10000 - 1) – 1001 = 1111 – 1001 = 0110


Now, the question is why the 1’s complement in binary number is basically changing
1’s to 0’s and 0’s to 1’s.? If we noticed from the two examples above, we see that the
1’s complement of a binary number, is basically subtracting each digit from 1.
For example, the 1’s complement of 1011000 is (1111111 – 1011000), and
the 1’s complement of 1001 is (1111 – 1001 ).
Now when subtracting binary digits from 1, we can have either (1-0 = 1) or (1-1 = 0)
which causes the bit to change from 0 to one, or from 1 to 0. thus the 1’s complement
of a binary number is formed by changing 1’s to 0’s and 0’s to 1’s.

So in general, For the decimal number system, the 9’s complement of a decimal number is
basically subtracting each decimal digit from 9. For the binary number system, the 1’s
complement of a binary number is basically subtracting each binary digit from 1. For the
Octal number system, the 7’s complement of an Octal number is basically subtracting each
Octal digit from 7. For the Hexadecimal number system, the F’s complement of a
Hexadecimal number is basically subtracting each Hexadecimal digit from F.
2) r’s Complements or (Radix Complement)
Given a number N in base r having n digits, the r’s complement of N is defined as (rn- N) for N !
= 0 and 0 for N = 0.
For example , what is the 10’s complement of the decimal (2389). N = 2389
R=10 N = 4

Thus the 10’s complement of


(2389) is
(rn- N) = (104-2389) = (10,000 -
2389) = 7,611

Lets take another example, what is


the 10’s complement of (546700)?
N = 546700
r = 10
n = 6 digits.
now, notice the following, from the above example, the 9’s complement of (546700) is
453,299, and the 10’s complement of (546700) is 453,300. Now, the questions is , do you
see any relation between (453,299) and (453,300)?
Yes, if we add 1 to the 9’s complement which is (453,299) we would get (453,300) which is
the 10’s complement since (453,299 + 1 = 453,300).
So, the 10’s complement is the 9’s complement + 1.
And if we look at the formula of (r-1)’s and r’s complement we would see the
following:-
R’s complement of N is (rn-N) and (r-1)’s complement of N is ((rn-1)-N). notice that
the
r’s complement can be obtained by adding 1 to the (r-1)’s complement Since
(rn-N) = (rn-1-N + 1) = ((rn-1)-N) + 1.

The same rule applies for any number system of base r.


For example, the 2’s complement of the binary number (101100) is
In 10’s complement of a decimal number, we said that it is (10n - N). Now 10n is a number
represented by 1 followed by n 0’s. Thus the 10’s complement of N can also be formed by
leaving all least significant 0’s unchanged, subtracting the first non-zero least significant
digit from 10, and subtracting all higher significant digits from 9.
For example, the 10’s complement of 246700 is 753300.
Notice here that the 10’s complement is obtained by leaving the two least significant 0’s
unchanged (246700), subtracting 7 from 10 (246700), and subtracting the other three
digits from 9 (246700).
Similarly, the 2’s complement of a binary numbers can be formed by leaving all least
significant 0’s and the first 1 unchanged, and replacing 1’s with 0’s and 0’s with 1’s in all
higher significant digits.
For example,

The 2’s complement of 1101100 is 0010100


The 2’s complement of 0110111 is 1001001
Question – 1)
1)Given the two binary numbers X = 1010100 (84) and Y = 1000011 (67), perform the
subtraction
a)X – Y b) Y – X using 1’s complements

1010100
1000011
- 1000011 - 1010100
1’ complement
1010100 1’ complement
1000011
+ 0111100 + 0101011
10010000 + 1101110
10010001
1’ complement
+(0010001) - (0 0 1 0 0 0 1)
Question – 2 )
Given the two binary numbers X = 1010100 and Y = 1000011, perform the subtraction
a)X – Y b) Y – X using 2’s complements

1010100
1000011
- 1000011 - 1010100
2’ complement
1010100 2’ complement
1000011
+ 0111101 + 0101100
10010001 1101111
+(0010001) 2’ complement
- (0 0 1 0 0 0 1)
Signed Numbers: -

In ordinary arithmetic, a negative number is indicated by a minus sign and a positive number by a plus sign.
Because of hardware limitations, computers must represent everything with binary digits. There are 3 ways to
represent a signed numbers.
1) Sign-Magnitude system
2) Signed-Complement
a. 1’s complement system
b. 2’s complement system

3) Sign- Magnitude System


In this system, the left-most bit in a signed binary number is the sign bit, which tells you whether the number is
positive or negative. We use 0 for positive, and 1 for negative.
For example, if we want to express the number +25 using 8 bits using this system, it would look like the
following:-
0 0011001 → +25
1 0011001 → -25
Notice that the only difference is the sign bit.
2) Signed-Complement
In this system, a negative number is indicated by its complement. In other word, this system negates the
numbers by taking it complement. Since positive numbers start with 0 in the left most position, the
complement will always start with a 1, indicating a negative number. The sign-complement system can
use either the 1’s complement or 2’s complement, but the 2’s complement is the most common… we will
see why?

A)1’s complement system


Positive numbers in the 1’s complement system are represented the same way as the sign-magnitude
system. However, Negative numbers are the 1’s complement of the corresponding positive numbers. For
example to represent +25 using this system using 8 bits,
it would be (00011001) → +25 and (11100110) →-25

B)2’s complement system


Again, Positive numbers in the 2’s complement system are represented the same way as the sign-
magnitude and 1’s complement system. However, Negative numbers are the 2’s complement of the
corresponding positive numbers. For example to represent +25 using this system using 8 bits,
it would be (00011001) → +25 and (11100111) →-25
To make the picture clearer, bellow we have two tables’ lists all possible 4 bits
unsigned and signed numbers.
Decimal Signed-2’s Compl. Signed-1’s Compl Signed-magnitude
+7 0111 0111 0111
+6 0110 0110 0110
+5 0101 0101 0101
+4 0100 0100 0100
+3 0011 0011 0011
+2 0010 0010 0010
+1 0001 0001 0001
+0 0000 0000 0000
-0 ----- 1111 1000
-1 1111 1110 1001
-2 1110 1101 1010
-3 1101 1100 1011
-4 1100 1011 1100
-5 1011 1010 1101
-6 1010 1001 1110
-7 1001 1000 1111
-8 1000 ------ ------

The decimal values for signed 4 bits binary numbers in the three representations
note that the positive numbers in all three representations are identical and have 0 in the left most
position. The 2’s complement has only one representation for 0, which is always positive. The other two
systems have either a positive 0 or negative 0, which is something not encountered in ordinary arithmetic
that’s why the 2’s complement system is the one used by computer systems.
Division
Definition:-
If a and b are integers with a≠0, we say that a divides b if
there is and integer c so that b = ac.

When a divides b we say that a is a factor of b and that b is


multiple of a.
The notation a|b means that a divides b
Examples:-
77|7 : False , bigger number can not divide smaller number
7|77 : True , because 77 = 7 * 11
24|24 : True, because 24 = 24 * 1
0|24 : False , only 0 is divisible by 0
24|0 : True, 0 is divisible by very number 0 = 24 * 0
Divisibility Theorems
For integers a ,b and c , it is true that

If a|b and a|c , then a|(b+c)


Example:-
3|6 and 3|9 , so 3|15.
17|34 and 17|170 then 17|204

If a|b, then a|bc for all integers c


Example:
5|10, so 5|20, 5|30, 5|40 , … so on

If a|b and b|c, then a|c


Example:-
6|12 and 12|144, then 6|144
The Division “Algorithm”
Let a be an integer and d a positive integer. Then
there are unique integers q and r, with 0 ≤r < d,
such that a = dq+r.

d is called the divisor


a is called the dividend
q is called the quotient
r is called the remainder
Example :-
When we divide 17 by 5 , we have
17 = 5*3 + 2
17 is the dividend
5 is the divisor
3 is the quotient
2 is the remainder
When we divide -11 by 3 , we have
-11 = 3*(-4) + 1 (The remainder can not be negative)
-11 is the dividend
3 is the divisor
-4 is the quotient
1 is the remainder
Modular Arithmetic
(a mod n) means the remainder when a is divided by n.
a mod n = r
a = dn + r for some integer d

Examples
17 mod 5 = 2 7 mod 11 = 7
20 mod 3 = 2 11 mod 11 = 0
-3 mod 11 = 8 -1 mod 11 = 10
25 mod 5 = 0 -11 mod 11 = 0

You might also like