Proof: We Will Give A Direct Proof of (I) - Suppose That A - B and A - C. Then, From The
Proof: We Will Give A Direct Proof of (I) - Suppose That A - B and A - C. Then, From The
Division
DEFINITION 1 If a and b are integers with a ≠ 0, we say that a divides b if there
𝑏
is an integer c such that b= ac, or equivalently, if is an integer. When a divides
𝑎
b we say that a is a factor or divisor of b, and that b is a multiple of a. The notation
a | b denotes that a divides b. We write 𝑎 ∤ b when a does not divide b.
EXAMPLE 1 Determine whether 3 | 7 and whether 3 | 12.
Solution: We see that 3∤7, because 7/3 is not an integer. On the other hand, 3 | 12
because 12/3 = 4.
THEOREM 1 Let a, b, and c be integers, where a ≠ 0. Then
The equalities in this corollary follow from these last two congruences by Theorem
3.
Arithmetic Modulo m
We can define arithmetic operations on Zm , the set of nonnegative integers less than
m, that is, the set {0, 1, . . . , m − 1}. In particular, we define addition of these
integers, denoted by +m by
a +m b = (a + b) mod m,
where the addition on the right-hand side of this equation is the ordinary addition of
integers, and we define multiplication of these integers, denoted by ·m by
a ·m b = (a · b) mod m,
where the multiplication on the right-hand side of this equation is the ordinary
multiplication of integers. The operations +m and ·m are called addition and
multiplication modulo m and when we use these operations, we are said to be doing
arithmetic modulo m.
EXAMPLE 6 Use the definition of addition and multiplication in Zm
to find 7 +11 9 and 7 ·11 9.
Solution: Using the definition of addition modulo 11, we find that
7 +11 9 = (7 + 9) mod 11 = 16 mod 11 = 5,
and
7 ·11 9 = (7 · 9) mod 11 = 63 mod 11 = 8.
Hence 7 +11 9 =5 and 7 ·119 = 8.
The operations +m and ·m satisfy many of the same properties of ordinary
addition and multiplication of integers. In particular, they satisfy these properties:
Closure If a and b belong to Zm, then a +m b and a ·m b belong to Zm.
Associativity If a, b, and c belong to Zm, then (a +m b) +m c = a +m (b +m c) and
(a ·m b) ·m c = a ·m (b ·m c).
Commutativity If a and b belong to Zm, then a +m b = b +m a and a ·m b = b ·m a.
Identity elements The elements 0 and 1 are identity elements for addition and
multiplication modulo m, respectively. That is, if a belongs to Zm, then a +m 0 = 0
+m a = a and a ·m 1 = 1 ·m a = a.
Additive inverses If a≠0 belongs to Zm, then m − a is an additive inverse of a
modulo m and 0 is its own additive inverse. That is a +m (m − a) = 0 and 0 +m 0 =
0.
Distributivity If a, b, and c belong to Zm, then a ·m (b +m c) = (a ·m b) +m (a ·m c)
and (a +m b) ·m c = (a ·m c) +m (b ·m c).
These properties follow from the properties we have developed for congruences
and remainders modulo m, together with the properties of integers. Note that we
have listed the property that every element of Zm has an additive inverse, but no
analogous property for multiplicative inverses has been included. This is because
multiplicative inverses do not always exists modulo m. For instance, there is no
multiplicative inverse of 2 modulo 6.
Remark: Because Zm with the operations of addition and multiplication modulo
m satisfies the properties listed, Zm with modular addition is said to be a
commutative group and Zm with both of these operations is said to be a
commutative ring. Note that the set of integers with ordinary addition and
multiplication also forms a commutative ring. Groups and rings are studied in
courses that cover abstract algebra.
Representations of Integers
THEOREM 1 Let b be an integer greater than 1. Then if n is a positive
integer, it can be expressed uniquely in the form
where k is a nonnegative integer, a0, a1, . . . , ak are nonnegative integers less than b,
and ak ≠ 0.
The representation of n given in Theorem 1 is called the base b expansion of n.
The base b expansion of n is denoted by (ak ak−1 . . . a1a0)b. For instance, (245)8
represents 2 · 82 + 4 · 8 + 5 = 165. Typically, the subscript 10 is omitted for base 10
expansions of integers because base 10, or decimal expansions, are commonly used
to represent integers.
BINARY EXPANSIONS Choosing 2 as the base gives binary expansions of
integers. In binary notation each digit is either a 0 or a 1. In other words, the binary
expansion of an integer is just a bit string. Binary expansions (and related expansions
that are variants of binary expansions) are used by computers to represent and do
arithmetic with integers.
EXAMPLE 1 What is the decimal expansion of the integer that has (1 0101 1111)2
as its binary expansion?
Solution: We
have
▲
(101011111)2 =1·28 + 0·27+1·26+ 0·25+1·24
+ 1·23+1·22+1·21+1·20 =351.
(7016)8 =7·83+0·82+1·8+6=3598.
Sixteen different digits are required for hexadecimal expansions. Usually, the
hexadecimal digits used are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F, where
the letters A through F represent the digits corresponding to the numbers 10 through
15 (in decimal notation).
EXAMPLE 3 What is the decimal expansion of the number with hexadecimal
expansion (2AE0B)16?
Solution: Using the definition of a base b expansion with b = 16 tells us that
(2AE0B)16 = 2 · 164 + 10 · 163 + 14 · 162 + 0 · 16 + 11 = 175627.
Each hexadecimal digit can be represented using four bits. For instance, we see
that (1110 0101)2 = (E5)16 because (1110)2 = (E)16 and (0101)2 = (5)16. Bytes, which
are bit strings of length eight, can be represented by two hexadecimal digits.
BASE CONVERSION We will now describe an algorithm for constructing the
base b expansion of an integer n. First, divide n by b to obtain a quotient and
remainder, that is,
n = bq0 + a0, 0 ≤ a0 < b.
The remainder, a0, is the rightmost digit in the base b expansion of n. Next, divide
q0 by b to obtain
We see that a1 is the second digit from the right in the base b expansion of n.
Continue this process, successively dividing the quotients by b, obtaining additional
base b digits as the remainders. This process terminates when we obtain a quotient
equal to zero. It produces the base b digits of n from the right to the left.
EXAMPLE 4 Find the octal expansion of (12345)10.
Solution: First, divide 12345 by 8 to obtain
12345 = 8 · 1543 + 1.
Successively dividing quotients by 8 gives
1543=8·192+7,
192 =8·24+0,
24 =8·3+0,
3 =8·0+3.
The successive remainders that we have found, 1, 7, 0, 0, and 3, are the digits
from the right to the left of 12345 in base 8. Hence,
(12345)10 = (30071)8.
CONVERSION BETWEEN BINARY, OCTAL, AND
HEXADECIMAL EXPANSIONS
Conversion between binary and octal and between binary and hexadecimal
expansions is extremely easy because each octal digit corresponds to a block of three
binary digits and each hexadecimal digit corresponds to a block of four binary digits,
with these correspondences shown in Table 1 without initial 0s shown. (We leave it
as Exercises 13–16 to show that this is the case.) This conversion is illustrated in
Example 5.
EXAMPLE 5 Find the octal and hexadecimal expansions of (11 1110 1011
1100)2 and the binary expansions of (765)8 and (A8D)16.
Solution: To convert (11 1110 1011 1100)2 into octal notation we group the
binary digits into blocks of three, adding initial zeros at the start of the leftmost block
if necessary. These blocks, from left to right, are 011, 111, 010, 111, and 100,
corresponding to 3, 7, 2, 7, and 4, respectively. Consequently, (11 1110 1011 1100) 2
= (37274)8. To convert (11 1110 1011 1100)2 into hexadecimal notation we group
the binary digits into blocks of four, adding initial zeros at the start of the leftmost
block if necessary. These blocks, from left to right, are 0011, 1110, 1011, and 1100,
corresponding to the hexadecimal digits 3, E, B, and C, respectively. Consequently,
(11 1110 1011 1100)2 = (3EBC)16.
To convert (765)8 into binary notation, we replace each octal digit by a block of
three binary digits. These blocks are 111, 110, and 101. Hence, (765)8 = (1 1111
0101)2. To convert (A8D)16 into binary notation, we replace each hexadecimal digit
by a block of four binary digits. These blocks are 1010, 1000, and 1101. Hence,
(A8D) 16 = (1010 1000 1101) 2.
Algorithms for Integer Operations
The algorithms for performing operations with integers using their binary
expansions are extremely important in computer arithmetic. We will describe
algorithms for the addition and the multiplication of two integers expressed in binary
notation. We will also analyze the computational complexity of these algorithms, in
terms of the actual number of bit operations used. Throughout this discussion,
suppose that the binary expansions of a and b are
so that a and b each have n bits (putting bits equal to 0 at the beginning of one of
these expansions if necessary).
We will measure the complexity of algorithms for integer arithmetic in terms of
the number of bits in these numbers.
ADDITION ALGORITHM Consider the problem of adding two integers in binary
notation. A procedure to perform addition can be based on the usual method for
adding numbers with pencil and paper. This method proceeds by adding pairs of
binary digits together with carries, when they occur, to compute the sum of two
integers. This procedure will now be specified in detail.
To add a and b, first add their rightmost bits. This gives
a0 + b0 = c0 · 2 + s0,
where s0 is the rightmost bit in the binary expansion of a + b and c0 is the carry,
which is either 0 or 1. Then add the next pair of bits and the carry,
a1 + b1 + c0 = c1 · 2 + s1,
where s1 is the next bit (from the right) in the binary expansion of a + b, and c1 is the
carry. Continue this process, adding the corresponding bits in the two binary
expansions and the carry, to determine the next bit from the right in the binary
expansion of a + b. At the last stage, add an−1, bn−1, and cn−2 to obtain cn−1 · 2 + sn−1.
The leading bit of the sum is sn = cn−1. This procedure produces the binary expansion
of the sum, namely, a + b = (snsn−1sn−2 . . . s1s0)2.
EXAMPLE 6 Add a = (1110)2 and b = (1011)2.
Solution: Following the procedure specified in the algorithm, first note that
a0 + b0 = 0 + 1 = 0 · 2 + 1,
a1 + b1 + c0 = 1 + 1 + 0 = 1 · 2 + 0,
We can compute ab using this equation. We first note that abj = a if bj = 1 and abj
= 0 if bj = 0. Each time we multiply a term by 2, we shift its binary expansion one
place to the left and add a zero at the tail end of the expansion. Consequently, we
can obtain (abj )2j by shifting the binary expansion of abj j places to the left, adding
j zero bits at the tail end of this binary expansion. Finally, we obtain ab by adding
the n integers abj 2j , j = 0, 1, 2, . . . , n − 1.
and
if a < 0 and r
> 0 then r
:= d − r
q := −(q + 1)