02c_Ch 1 Solutions

advertisement
4
JAVA METHODS ANSWERS AND SOLUTIONS TO EXERCISES
Chapter 1. An Introduction to Hardware, Software, and the Internet
1.
(a) F (b) F (c) F
2.
q
q
3.
q
4.
(a)
A
B
(b)
A
B
5.
D
6.
(a) T -- megabyte is a measure of capacity, not specific media
(b) F -- files are created by the operating system
(c) F -- only the boot record is in ROM. Actually, it can boot any operating system that it can find
on disk.
7.
If you don't feel like fiddling with screws, the Internet is a good resource.
8.
(a) S (b) H (c) S (d) H (e) H (f) S
9. If you can see this file, you have Adobe Reader installed.
10.
(a) F (programs must be loaded into RAM before they can be executed)
(b) T (however, if you refer to “ASCII” characters as a subset of Unicode, then each “ASCII”
character, as all Unicode characters, is represented in two bytes, with the first byte equal to 0)
(c) T (d) T
CHAPTER 1
11.
(a) 23
8 (b) 28
256 (c) 216
5
65536
12.
Binary
(a)
(b)
(c)
(d)
(e)
(f)
(g)
13.
00000010
00000111
10000000
00001011
11000011
11110101
00000101 10010010
Decimal
Hex
2
7
128
11
195
245
1426
02
07
80
0B
C3
F5
0592
210 1024
14.
512 * 512 * 8 bits = 256 KB. (It takes 8 bits to represent 256 28 different values.)
15.
101100002 = B0 hex.
16.
Yes. You can use 2 bits per square, for example 00 = empty, 01 = ‘o’, 11 = ‘x’. Then you need 9 *
2 = 18 bits = 2.25 bytes.
17.
A player finds all columns where the number of 1s is odd and forms a number x whose binary
representation has 1s in these columns and 0s elsewhere (this operation is equivalent to XORing all
corresponding bits in the binary representations of numbers of stones in the piles). Suppose in x
the most significant digit equal to 1 is found in position k, (that is, 2k d x 2k 1 ). The player then
finds a pile where the number of stones n has 1 in position k, takes the binary representation of the
number of stones in that pile and flips the required bits in it to “balance” all columns to even
numbers of 1s (this is equivalent to XORing the corresponding bits in x and n) and leaves that
many stones in that pile. For example, if piles have 1, 3, 5 and 7 stones —
1 = 0012
3 = 0112
5 = 1012
7 = 1112
=======
000
— then all columns are “even,” so the second player should be able to win. If the first player takes
five out of seven, we get
1 = 0012
3 = 0112
5 = 1012
7 = 0102
=======
101
To balance, the second player should take all stones from the “5” pile.
6
JAVA METHODS ANSWERS AND SOLUTIONS TO EXERCISES
18.
01 20 12
22 11 00
10 02 21
12
03
44
30
21
01
42
33
24
10
40
31
22
13
04
=>
34
20
11
02
43
23
14
00
41
32
1 6 5
8 4 0
3 2 7
=>
=>
2 7 6
9 5 1
4 3 8
7 1 20 19 13
3 22 16 10 9
24 18 12 6 0
15 14 8 2 21
11 5 4 23 17
=>
8 2 21 20
4 23 17 11
25 19 13 7
16 15 9 3
12 6 5 24
19.
B
20.
(a) H (b) H (c) S (d) S (e) H (f) H
21.
See, for example, http://www.computerhistory.org/internet_history/.
14
10
1
22
18
Download