3.6 (evens) - SECTION 3.6 Integers and Algorithms 2. 10....

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: SECTION 3.6 Integers and Algorithms 2. 10. 12. 14. . a) 1+2+8+16=27 To convert from decimal to binary, we successively divide by 2. We write down the remainders so obtained from right to left; that is the binary representation of the given number. a) Since 321/2 is 160 with a remainder of 1, the rightmost digit is 1. Then since 160/2 is 80 with a remainder of 0, the second digit from the right is 0. We continue in this manner, obtaining successive quotients of 40, 20, 10, 5, 2, 1, and 0, and remainders 010, 0, 0, 0, 1, 0, and 1. Putting all these remainders in order from right to left we obtain (1 0100 0001)2 as the binary representation. \Ve could, as a check, expand this binary numeral: 20 + 2'3 + 28 = 1 + 64 + 256 : 321. b) \Ve could carry out the same process as in part (21). Alternatively, we might notice that 1023 : 1024 e 1 : 21° — 1. Therefore the binary representation is 1 less than (100 0000 0000)2, which is clearly (11 1111 1111);. c) If we carry out the divisions by 2, the quotients are 50316, 251.58, 12579, 0280, 3144, 1572, 7'86, 393, 196, 98, 49, 24, 1‘2, 0', 3, 1, and 0, with remainders 010, 0,0,1,1, 0, 0, 0, 1, 0, 0, 1, 0,0, 0, 1,and 1. Putting the remainders in order from right to left We have (1 1000 1001 0001 1000);. b) 1+4+16+32+128+512=093 c) 2+4+8+16+32+128+256+512=958 d) 1+2+4+8+16+1024+204S+4096+8192+16384 231775 . Following Example 6, we simply write the binary equivalents of each digit. Since (A)13 : (1010)2, (13)”,- : (1011)2, ((1)16 2 (1100)), (Dhs : (1101)}, (E)16 = (111012, and (F)16 = (1111)2, we have 2 (10111010110111111010110011101101)g. Following the convention shown in Exercise 3 of grouping binary digits by fours, we can write this in a more readable form as 1011 1010 1101 1111 1010 1100 1110 1101. . We follow the method stated in Example 6. 3) 11110111 becomes F7 b) 1010 1010 1010 becomes AAA e) 111 0111 0111 0111 becomes 7777' Following Example 6, we simply write the hexadecimal equivalents of each group of tour binary digits. Note that we group from the right, so the left—most group, which is just 1, becomes 0001. Thus we have (0001 1000 0110 0011).2 :(1863)15. ' Let (. . . h]h]h@)16 be the hexadecimal expansion of a positive integer. The value of that integer is, therefore, h0+h]'16+h2-162+‘-‘2110+111-24 +h2'28+"'. its binary expansion ((Jigb,20?10i0)2, then h,- : (1,0 + 20“ + 4052 + 811,3. Therefore the value of the entire number is 000 + 2001 + 4002 + 8003 + (1)10 + 2011 + 4012 + 8013) ' 24 + (020 + 2021+ 4022 + 8023) - 28 + ' - ' Z 000 + 2001 + 400-; + 8003 + 24010 + 2‘30“ + 25012 + 27013 + 23020 + 29021 + 210022 + 211023 + ---, which is the value of the binary expansion . . 02302202102001301201jblobogbflgbglbgfl)2. If we replace each hexadecimal digit h,- by This is exactly the same as what we can do with hexadecimal expansion, replacing groups of four with groups of three. Specifically, convert each octal digit into its 3-digit binary equivalent. (011000110)2. For example, (30(3):, 2, 74 16. 18. 20. 22. 24. Chapter 3 The Fundamentals: Algorithms, the Integers, and ri-Iati‘ices Since we have procedures for converting both octal and hexadecimal to and from binaryr (Example 6 and Exercises 13—15), to convert from hexadecimal to octal, we first convert from hexadecimal to binary and then convert from binary to octal. We work through binary in each case; see Exercises 16 and 17. Thus (12345670)5 2 (001 010 011 100101 110111 000)2 2 (0010 1001 11001011 1011 1000)2 2 (2QCBB8)15 and (ABB093BABBA)16 2 (1010 1011 1011 0000 1001 0011 1011 1010 1011 1011 1010)2 2 (010 101 011 101 100 001001 001 110111 010 101 110111010)2 2 (2.535411107250733. 1n effect, this algorithm computes 11 mod 645, 112 mod 645, 114 mod 645, 11*3 mod 645, 1116 mod 645, .., and then multiplies (modulo 645) the required values. Since 644 2 (1010000100)2, we need to multiply together 11’1 mod 645, 11128 mod 645, and 11“2 mod 645, reducing modulo 045 at each step. We compute by repeatedly squaring: 112 mod 645 2 121, 114 mod 645 2 1212 mod 645 2 14641 mod 645 = 451, 118 mod 045 2 4512 mod 045 2 203401 mod 045 2 220, 1116 mod 045 2 2202 mod 045 2 5107011100 045 2 121. At this point we notice that 121 appeared earlier in our calculation, so we have 1132 mod 645 2 1212 mod 045 2 451, 1164 mod 045 2 4512 mod 045 2 220, 11128 mod 045 2 220-2 mod 045 2 121, 11256 mod 645 2 451, and 11512 mod 645 2 226. Thus our final answer will be the product of 451, 121, and 226, reduced modulo 645. We compute these one at a time: 451 - 121 mod 645 2 54571 mod 045 2 391, and 391 - 226 mod 645 2 88366 mod 61-15 2 1. So 116/” mod 645 2 1. A computer algebra system will verify this; use the con'uriand “1 85“ 644 mod 645;” in Maple, for example. The ampersand here tells Maple to use modular exponentiation, rather than first computing the integer 116“, which has over 600 digits, although it could certainly handle this if asked. The point is that modular exponentiation is much faster and avoids having to deal with such large numbers. In effect this algorithm computes powers 123 mod 101, 1232 mod 101, 1234 mod 101, 1238,mod 101, 12315 mod 101, ..., and then multiplies (module 101) the required values. Since 1001 2 (1111101001)2, we need to multiply together 123 mod 101, 1238 mod 101, 12332 mod 101, 1236'1 mod 101, 123-128 mod 101, 1232'36 mod 101, and 123‘-112 mod 101, reducing modulo 101 at each step. we compute by repeatedly squaring: 123 mod 101 2 22, 123'2 mod 101 2 222 mod 101 2 484 mod 101 2 80, 123" mod 101 2 802 mod 101 2 0400 mod 101 2 37, 1238 mod 101 2 372 mod 101 2 1309 mod 101 2 50, 12316 mod 101 2 562 mod 101 2 3136 mod 101: 5, 12332 mod 101:— 52 mod 101 2 25, 12354 mod 1012 252 mod 101: 025 mod 101 219, 123128 mod 101 2 10‘2 mod 101 2 301 mod 101 2 58, 1232‘36 mod 10:1 2 582 mod 101 2 3364 mod 101 2 31, and 123512 mod 101 2 312 mod 101 2 961 mod 101 2 52. Thus our final answer will be the product of 22, 56, 25, 19, 58, 31, and 52. We compute these one at a time modulo 101: 22 - 56 is 20, 20-25 is 90, 90-19 is 0, 0-58 is 45, 45-31 is 82, and finally 82-52 is 22. So 1231001 mod 101 2 22. To apply’ the Euclidean algorithm, we divide the larger number by the smaller, replace the larger by the smaller and the smaller by the remainder of this division, and repeat this process until the remainder is 0. At that point, the smaller number is the greatest common divisor. a) gcd(1,5) 2 gcd(1,0) 2 l b) gcd(100,101) 2 gcd(100, 1) 2 gr:d(1,0) 21 c) gcd(123,277 2 gcd(123,31) 2 gcd(31,30) = gcd(30, 1) 2 gcd(1,0) 2 1 d) gcd(1529,14039) 2 gcd(l529, 278) 2 gcd(278,139) 2 gcd(139, 0) 2 139 e) gcd(1529, 14038) 2 gcd(1529,277) 2 ged('277, 144) 2 gcd(144,133) 2 gcd(133,11) 2 gcd(11, 1) 2 gcd(1,0) 2 1 r) gcd(11111, 111111) 2 gcd(11111, 1) 2 gcd(1,0) 21 Section 3.6 26. 28. 30. 32. 34. 36. 38. 40. 42. Integers and Algorithms 75 “Ne need to divide successively by 51'), 34, 21, 13, 8, 5, 3, 2, and 1, so 9 divisions are required. a)5:973—1 b) 13=9+3+1 c)37=27+9+1 d)79:81—3+1 The key fact here is that 10 E 71 (mod 11), and so 10"" E (71% (mod 11). Thus 10“ is congruent to 1 if .1: is even and to E1 if 1:. is odd. Let the decimal expansion of the integer a be given by (nn_1a.,,,2.. .03a201au)1g. Thus a : 10’1‘1an_1+10”‘2an22 ++10o1 + (1,]. Since 10’? E (El)" (mod 11)_, we have n E ia,,_1 $ and + - - - — a3 + a2 — a, + a0 (mod 11), where signs alternate and depend on the parity of n. Therefore a. E 0 (mod 11) if and only if ((1.0 + a; + 0.1 + ---) — (01 + 03 + (1.5 + -- odd and even indexed terms, is congruent to 0 (mod 11). Since being divisible by 11 is the same as being which we obtain by collecting the congruent to 0 (mod 11), we have proved that a positive integer is divisible by 11 if and only if the sum of its decimal digits in even—nun'ibere('l positions minus the sum of its decimal digits in odd-numbered positions is divisible by 11. a) Since the binary representation of 22 is 10110, the six bit. one’s complement representation is 010110. b) Since the binary representation of 31 is 11111, the six bit one’s complement representation is 011111. c) Since the binary representation of 7 is 111 , we complement 000111 to obtain 111000 as the one’s comple- mth representation of E7. d) Since the binary representation of 19 is 10011, we complement 010011 to obtain 101100 as the one‘s complement representation of —10. Every 1 is changed to a 0, and every 0 is changed to a 1. We just combine the two ideas in Exercises 34 and 35: to form a E l), we compute a+ (Eb), using Exercise 34 to find El) and Exercise 35 to find the sum. Following the definition, we find the two's complement expansion of a positive number simply by representing it in binary, usingr six bits; and we find the two’s complement expansion of a negative number at; by representing 25 7 .17 in binary using five hits and preceding it with a 1. a) Since 22 is positive, and its binary expansion is 10110, the answer is 010110. b) Since 31 is positive, and its binary expansion is 11111, the answer is 011111. C) Since E7 is negative, we first find the 57bit binary expansion of 25’ E 7 : 25, namely 11001, and precede it by a 1, obtaining 111001. (:1) Since E19 is negative, we first find the 5-bit binary expansion of 2‘3 E 19 : 13, namely 01101, and precede it by a 1, obtaining 101101. We can experiment a bit to find a convenient algorithm. We saw in Exercise 38 that the expansion of 77 is 1l1001, while of course the expansion of 7 is 000111. Apparently to find the expansion of —-m from that of ‘1}? we complement each bit and then add 1, working in base 2. Similarly, the expansion of 78 is 111000, whereas the expansion of 8 is 001000; again 110111 + 1 : 111000. At the extremes (using six bits) we have 1 represented by 000001, so *1 is represented by 111110 + 1 : 111111; and 31 is represented by 011111, so 731 is represented by 100000 + 1 : 100001. we just combine the two ideas in Exercises 40 and 41: to form a — b, we compute (1+ (—0) , using Exercise 40 to find —b and Exercise 41 to find the sum. 76 44. 46. 48. 50. 52. 54. 56. Chapter 3 The Fundamentals: Algorithms, the Integers, and Matrices If the number is positive (i.e., the left—most bit is 0), then the expansions are the same. If the number is negative {i.e., the left-most bit is 1), then we take the one’s complement representation and add 1, working in base 2. For example, the one’s complement representation of —19 using six bits is, from Exercise 32, 101100. Adding 1 we obtain 101101, which is the two’s complement representation of ~19 using six bits, from Exercise 38. We obtain these expansions from the top down. For example in part (e) we compute that 7! _> 1000 but til 3 1000, so the highest factorial appearing is 6! = 721). We use the division algorithm to-find the quotient and remainder when 1000 is divided by 720, namely 1 and 280, respectively. Therefore the expansion begins 1 -6! and continues with the expansion of 280, which we find in the same manner. a) 2:2! b) 7:3!+1! c) 19:3-3!+1! d) 87=3-4!+2-3!+2!+1! e)1000:6!+2-5!+41+2-3l+2-2! r)1000000:2-9!+6-8!+6-7!+2.6!+5.5!+4!+2.3!+2-2! The algorithm is essentially the same as the usual grade—school algorithm for adding. We add from right to left, one column at a time, carrying to the next column ifnecessary. A carry out of the column representing i! is needed whenever the sum obtained for that column is greater than i, in which case we subtract :1 + 1 from that digit and carry 1 into the next column (since (i + 1)! : (r' + 1) - ii). The partial products are 11100 and 1110000, namely 1110 shifted one place and three places to the left. We add these two numbers, obtaining 10001100. Subtraction is really just like addition, so the number of bit Operations should be comparable, namely 0(a). More specifically, if we analyze the algorithm for Exercise 51, we see that the loop is executed n times, and only a few operations are performed during each pass. In the worst case, each bit of a has to be compared to each bit of b, so 0(a) comparisons are needed. An exact analysis of the procedure given in the solution to Exercise 53 shows that n + 1 comparisons of bits are needed in the worst case, assuming that the logical “such' condition in the whiie 100p is evaluated efficiently from left to right (so that (10 is not compared to [)0 there). A multiplication modulo m. consists of multiplying two integers, each at most logm bits long (since they are less than 771), followed by a division by m, which is also log m bits long. Thus this takes (log in.)2 hit operations by Example 10 and the analysis of Algorithm 4 mentioned in the text. This is what goes on inside the 100p of Algorithm 5. The loop is iterated log n. times. Therefore the total number of bit Operations is O((logm)210g n). ...
View Full Document

This note was uploaded on 02/18/2012 for the course MATH 640:244 taught by Professor Ming during the Spring '09 term at Rutgers.

Page1 / 4

3.6 (evens) - SECTION 3.6 Integers and Algorithms 2. 10....

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online