miun.logo

Integers and Congruences - Part I




1. Division Algorithm

Why study integers and divisibility?
- binary, octal, hexadecimal systems
- solving equations such as 36x+48y=56 where x and y must be integers
- latin squares
- mod n
- prime numbers - used for example in cryptography.

We begin with division. When we divide an integer by another integer, we usually look for a remainder (rest) which is as small as possible while remaining non-negative. For example, if we divide 27 by 6 we get 4 remainder 3. What does that mean? It means that 27=6times4 + 3. However, we could also write 27=3times6 + 9, which means we get a remainder of 9.

We are making two assumptions

The next theorem shows that our assumptions are correct.

Theorem: Division algorithm

For all integers a and b > 0, there exist unique integers q and r such that a=qb+r where 0 r < b.

ProofComments

First we show that there are integers q, r where r ge 0 such that a=bq+r. Then we show that r< b, and finally that q and r are unique.

Now, what is it we want to prove? We can break it down into several steps.
  • Show there are integers q and r so that a=bq+r where r ge 0
  • Show that r < b.
  • Show that r and q are unique.
Now, taking q=0 and r=a, we have a=bq+r=0b+q. How can we do this? If we take an example, we can write 27=4times0 + 27. In this case q=0 and r=27ge0 - in general this is a=btimes0 + a, so there is a non-negative remainder.
Let S be the set of all non-negative integers r such that a=bq+r. Let r0 be the smallest element in S. Suppose r0 ge b. We will obtain a contradiction. As r0 is an element in S, we can write a=bq0 + r0 for some integer q0. As r0 ge b, r0-b is also non-negative. Hence a=(q0+1)b+ (r0-b), where r0 ge 0, so (r0 - b) is an element of S. Now r0 > r0 - b ge 0, so r0 - b is a smaller element of S than r0 which we assumed to be the smallest element of S. This is a contradiction. Hence there is an integer r such that a=bq+r and b ge r > 0. Now to show that r < b we use contradiction and a useful trick. We suppose r > b and that r is the smallest non-negative remainder when a is divided by b. We get a contradiction by finding a remainder which is smaller than our supposed smallest element! There is an axiom - the Well-Ordering Axiom which enables us to be sure that there is a smallest element in any set of non-negative integers. (This is covered more thoroughly in Diskret Matematik B.)
Note that we say an integer r as we do not yet know if there is just one integer r. In mathematics we need to be precise - if there is a possibility that there is more than one, we should say 'a' and not 'the'.
Suppose r1, r2, q1 and q2 are integers such that a=bq1+r1 (1) and a=bq2+r2 (2) where 0 le r1 < r2 < b. Subtracting (1) from (2), we get b(q1-q2)+(r1-r2)=0, that is b(q1-q2)=r2-r1 > 0. As r1 < r2 < b, we have r2-r1 < b. It is also a multiple of b, which is a contradiction as there are no integer multiples of b in the given range. Hence there is are unique q and r satisfying the conditions. Now we know that integers q and r, satisfying the conditions given, exist. We need to show they are unique. Again, we use a useful trick. We suppose they are not unique and get a contradiction.

We call this unique remainder r such that 0 le r < b the principal remainder.

Consequences of the uniqueness of remainders

There are two important consequences of the uniquess proved in the theorem above. The first is that we know that an integer is either even or odd, but never both and the second is discussed in the next section.

2. Position Systems

That the remainder is unique has important consequences. Consider the number 329. What does that mean? It means

3times102 + 2times10 + 9times1.

Is there any other way to write this number in our normal decimal system? We 'know' there is not because of our previous experience. The reason is because the principal remainder is unique. When we divide 325 by 100 we get 3 remainder 25, so we write 3 in the hundreds position. When we divide 25 by 10 we get 2 remainder 5, so we want 2 in the tens position. Finally we have 5 left, so we write that in the units position to get 325. We had no choice at any stage as to what to write where.

Now we will look at different position systems and how we can convert from denary (base 10) to other bases.

Denary to Binary

How can we write 327 in binary?

We need to find the quotient (kvot) and principal remainder when 327 is divided by 256=28. We get 1 remainder 71.
We now need to find the quotient and remainder when 71 (the previous remainder) is divided by 128=27. This gives0 remainder 71.
Continuing, we divide by 64=26 to get 1 remainder 7.
Dividing 7 by 32=25 we get0 remainder 5.
Dividing 7 by 16=24 we get 0 remainder 5.
Dividing 7 by 8=23 we get 0 remainder 5.
Dividing 7 by 4=22 we get 1 remainder 3.
Dividing 3 by 2=21 we get1 remainder 1,
and finally dividing 1 by 1 we get 1 remainder 0.
This means that 32510 (the subscript indicates the base) can be written as 1010001112. (Always a good idea to check an answer if possible: 1010001112 = (256+64+4+2+1)10 = 32710.)

There is a problem with this method. If we want to write the number x in binary, we have to calculate all the powers of 2 which are at most x. When x is small, this isn't too bad, but what if x is large? We really want a more practical method. Next we consider such a method.

We divide 327 by 2, and then we divide the quotient by 2 and so on.

327=2times163 + 1
163=2times81+ 1
81=2times40+ 1
40=2times20 + 0
20=2times10 + 0
10=2times5 + 0
5=2times2 + 1
2=2times1 + 0
1=2times0 + 1
Stop when quotient is 0.

Now read the final column above in reverse order. We get 101000111, which is exactly what we had before.

How did the calculation work? When we divided by 2 the first time, we got

327=163times2+1.

Now we continue with 163, so we have 163=81times2+1. We substitute this for 163 in the above calculation to get have

327=163times2 + 1 = (81times2 + 1)times2 + 1 = 81times22 + 1times2 + 1.

Replacing 81 in the above, we get

327=(40times2+1)times22 + 1times2 + 1 = 40times23 + 1times22 + 1times2 + 1.

Replacing 40 gives

327= (20times2+0)times23 + 1times22 + 1times2 + 1 = 20times24 + 0times23 + 1times22 + 1times2 + 1.

Replacing 20 gives

327= (10times2 + 0)times24 + 0times23 + 1times22 + 1times2 + 1 = 10times25 + 0times24 + 0times23 + 1times22 + 1times2 + 1

Replacing 10 gives

327 = (5times2+0)times25 + 0times24 + 0times23 + 1times22 + 1times2 + 1 = 5times26 + 0times25 + 0times24 + 0times23 + 1times22 + 1times2 + 1

Replacing 5 gives

327= (2times2+1)times26 + 0times25 + 0times24 + 0times23 + 1times22 + 1times2 + 1
  = 2times27 + 1times26 + 0times25 + 0times24 + 0times23 + 1times22 + 1times2 + 1

And finally, replacing 2 gives

327= (1times2+0)times27 + 1times26 + 0times25 + 0times24 + 0times23 + 1times22 + 1times2 + 1
  = 1times28 + 0times27 + 1times26 + 0times25 + 0times24 + 0times23 + 1times22 + 1times2 + 1
  = 1010001112.

Example

To write 327 in base 8, we apply the same technique as above.

327 = 40times8 + 7
40 = 5times8 + 0
5 = 0times8 + 5
Quotient was 0 in previous row,
so stop and write down the
remainders in reverse order.

Hence 327=5078. (Check: 5times82 + 0times81 + 7 = 5times64+7=327.)

Exercises

  1. Write 5295 in binary.
  2. Write 100101102 in denary (base 10).
  3. Write 23956 in base 8.
  4. Write 234643 in hexidecimal (base 16) using the digits 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F.
  5. Sing '100 buckets of bits on the bus' which is in the 'fortune' database of most unix systems or check out http://www.poppyfields.net/filks/00028.html.

Answers


Sarah Norell
c/o Pia Heidtmann
© MITTUNIVERSITETET
Institutionen för Teknik, Fysik och Matematik
Mittuniversitetet
SE-851 70 SUNDSVALL
Sweden
Updated 060330.