Discrete Mathematics and Its Applications with MathZone

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
ICS 6D ( Discrete Mathematic): Solution to Homework #4 Section 3.6 4. Converting integers from binary to decimal notation is done by adding up appropriate powers of 2, depending on the bits in the binary representation, as in Example 1 on page 219. Specifically, ( b n . . . b 1 b 0 ) 2 = n i =0 b i 2 i . For example, (1 1011) 2 = 1 2 0 + 1 2 1 + 0 2 2 + 1 2 3 + 1 2 4 = 1 + 2 + 8 + 16 = 27. 2. The last bit of base-2 representation of n is ( n mod 2), and to get the remaining bits recurse on ( n div 2). This procedure is explained in Example 5 on page 221. This way you get (321) 10 = (1 0100 0001) 2 , because 321 mod 2 = 1, and (321 1) div 2 = 160 160 mod 2 = 0, and (160 0) div 2 = 80 80 mod 2 = 0, and (80 0) div 2 = 40 40 mod 2 = 0, and (40 0) div 2 = 20 20 mod 2 = 0, and (20 0) div 2 = 10 10 mod 2 = 0, and (10 0) div 2 = 5 5 mod 2 = 1, and (5 1) div 2 = 2 2 mod 2 = 0, and (2 0) div 2 = 1 1 mod 2 = 1, and (1 0) div 2 = 0, so we stop here. Now you just need to order the bits appropriately, namely the least-significant bit was first and the most- significant one was last. Similarly (1023) 10 = (11 1111 1111) 2 . You can verify that these representations are correct by checking that 321 = 2 0 + 2 6 + 2 8 and that 1023 = 2 0 + 2 1 + 2 2 + 2 3 + 2 4 + 2 5 + 2 6 + 2 7 + 2 8 + 2 9 . 1 12. By theorem 1 on page 219 we have that ( a k . . . a 0 ) 16 = k summationdisplay i =0 a i 16 i If you denote the binary representation of hexadecimal digit ( a i ) 16 as ( b 4 i +3 b 4 i +2 b 4 i +1 b 4 i ) 2 , then a i = 3 summationdisplay j =0 b 4 i + j 2 j and therefore a i 16 i = a i 2 4 i = ( 3 summationdisplay j =0 b 4 i + j 2 j ) 2 4 i = 3 summationdisplay j +0 b 4 i + j 2 4 i + j Consequently, ( a k . . . a 0 ) 16 = k summationdisplay i =0 a i 16 i = k summationdisplay i =0 3 summationdisplay j +0 b 4 i + j 2 4 i + j But if you denote 4 i + j as t , this can be re-written as 4 k +3 summationdisplay t =0 b t 2 t And therefore ( a k . . . a 0 ) 16 = ( b 4 k +3 . . . b 0 ) 2 where each block of four consecutive bits ( b 4 i +3 . . . b 4 i ) 2 is a binary representation of ( a i ) 16 . 1 Actually if you remember different powers of 2, and it’s very useful for a computer-science to remember powers of 2, you might notice that 1023 + 1 = 1024 = 2 10 , and since 2 10 = (100 0000 0000) 2 , it follows that 2 10 - 1 = (100 0000 0000) 2 - (1) 2 = (11 1111 1111) 2 . Page 1 of 5
Image of page 1

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

View Full Document Right Arrow Icon
ICS 6D ( Discrete Mathematic): Solution to Homework #4 6,8. Now converting between hexadecimal and binary should be easy. For example, ( BAD ) 16 = (1011 1010 1101) 2 because ( B ) 16 = 11 = (1011) 2 , ( A ) 16 = 10 = (1010) 2 , and ( D ) 16 = 13 = (1101) 2 , because ( B ) 16 = 11 = (1011) 2 , ( A ) 16 = 10 = (1010) 2 , and ( D ) 16 = 13 = (1101) 2 . Similarly ( BADFACED ) 16 = (1011 1010 1101 1111 1010 1100 1110 1101) 2 Conversely, (1111 0111) 2 = ( F 7) 16 because (1111) 2 = 15 = ( F ) 16 and (0111) 2 = 7 = (7) 16 , etc. If you are not sure how these conversions work, read the examples in the book, ask the TA to go over it, practice with even-numbered exercises which have the solutions at the end of the book, and come to our office hours. 20. We are to compute 11 644 mod 645. To use the square-and-multiply exponentiation algorithm we need to first represent the exponent in binary. Here 644 = (10 1000 0100) 2 . If you use the algorithm from the slides, you start with k = 9 and x = 1, and here are each iterations of the main loop: Since a 9 = 1, x becomes ( x 11) 2 = 121 mod 645 = 121 Since a 8 = 0, x
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern