solutions 4

Discrete Mathematics and Its Applications with MathZone

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

View Full Document Right Arrow Icon

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

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

Unformatted text preview: 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 ) 2 = n i =0 b i 2 i . For example, (1 1011) 2 = 1 2 + 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 + 2 6 + 2 8 and that 1023 = 2 + 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 ) 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 ) 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 ) 16 = ( b 4 k +3 ...b ) 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 its 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 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....
View Full Document

This homework help was uploaded on 01/30/2008 for the course ICS 6D taught by Professor Jarecki during the Fall '07 term at UC Irvine.

Page1 / 5

solutions 4 - ICS 6D ( Discrete Mathematic): Solution to...

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

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