Solutions to other tests:
  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17  

Mathematics for the Digital Age
and
Programming in Python


>>> Second Edition

Test 7

1.
D
2.
B
3.
C
4.
D
5.
B
6.
A
7.
(a), (b)
8.
D
9.
C
10.
B
11.
(a), (b), (c)
12.
(c)
13.
B
14.
A
15.
C
16.
(a), (c)
17.
(a), (b)
18.
(b)
19.
C
20.
(a), (b), (c), (d)

21.
22.
r & 0b1011 == 0b1000 
or
r & 0x0B == 0x08
23.
0xBCE1
24.
def processed(b): return b & ~((b << 1) & (b >> 1))
25.
def rotate(bits, k): return (bits >> k) | ((bits << (8 - k)) & 0xFF)
26.
(a) def count_1_bits(n): count = 0 while n > 0: count += n & 1 n >>= 1 return count (b) bitcounts = [0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4] (c) def count_1_bits(n): count = 0 while n > 0: count += bitcounts[n & 0b1111] n >>= 4 return count (d) def match(n, p): return 16 - count_1_bits(n ^ p)




Copyright © 2010 by Skylight Publishing