@@ -11,10 +11,10 @@ Convert the binary number 101101 to decimal:
1111Answer: 2^5 + 2^3 + 2^2 + 2^0 = 32 + 8 + 4 + 1 = 45
1212
1313Which is larger: 1000 or 0111?
14- Answer: 1000 because 1000 is 8 and 0111 is 7
14+ Answer: 1000 is larger because 1000 has more places
1515
1616Which is larger: 00100 or 01011?
17- Answer: 01011 because 01011 is 11 and 00100 is 4
17+ Answer: 01011 is larger because it has more places
1818
1919What is 10101 + 01010?
2020Answer: 11111
@@ -34,8 +34,8 @@ Answer: 2 bits as 00 = 0, and 11 = 3
3434How many bits would you need in order to store the numbers between 0 and 1000 inclusive?
3535Answer: 2^9 = 512
36362^8 = 256
37- 2^7 = 128
38- 2^6 = 64
37+ 2^7 = 128
38+ 2^6 = 64
39392^3 = 8
4040512 + 256 + 128 + 64 + 32 + 8 = 1000
4141b1111101000 = 1000
@@ -44,39 +44,38 @@ we need 10 bits
4444How can you test if a binary number is a power of two (e.g. 1, 2, 4, 8, 16, ...)?
4545Answer: 1, 10, 100, 1000, 10000
46461, 2, 4, 8, 16
47- If the binary starts with 1 or 1 followed by 0s, it will be a power of two.
47+ If the binary number is 1 or 1 followed by 0s, it will be a power of two.
4848We can use regexp to test the binary number.
4949
50- function testPowerOfTwo(binaryNumber) {
51- return /^0*10*$/.test(String(binaryNumber))
52- }
50+ function testPowerOfTwo(binaryNumber) {
51+ return /^0* 10* $/.test(String(binaryNumber))
52+ }
5353
5454Convert the decimal number 14 to hex.
5555Answer: 10 = A, 11 = B, 12 = C, 13 = D, 14 = E
5656
5757Convert the decimal number 386 to hex.
58- Answer: F = 15,
59- 386 / 15 = 25.7333
60- 386 - (F * 25) = 11
61- So, 386 = F* 25+B
58+ Answer: 386 - 16^2 = 130
59+ 130 - 16 x 8 = 2
60+ hex: 182
6261
6362Convert the hex number 386 to decimal.
64- Answer:
63+ Answer: 3 x 16^2 + 8 x 16 + 6 x 1 = 902
6564
6665Convert the hex number B to decimal.
67- Answer:
66+ Answer: 11
6867
6968If reading the byte 0x21 as a number, what decimal number would it mean?
70- Answer:
69+ Answer: 2 x 16 + 1 X 1 = 33
7170
7271If reading the byte 0x21 as an ASCII character, what character would it mean?
73- Answer:
72+ Answer: !
7473
7574If reading the byte 0x21 as a greyscale colour, as described in "Approaches for Representing Colors and Images", what colour would it mean?
76- Answer:
75+ Answer: As the byte 0x21 is 33 in decimal, which is in the range of 0 full black to 255 full white. The color is close to black.
7776
7877If reading the bytes 0xAA00FF as an RGB colour, as described in "Approaches for Representing Colors and Images", what colour would it mean?
79- Answer:
78+ Answer: AA (170) means middle high red, 00 means no green, and FF (255) means full blue. The colour should be purple.
8079
8180If reading the bytes 0xAA00FF as a sequence of three one-byte decimal numbers, what decimal numbers would they be?
82- Answer:
81+ Answer: 170, 0, 255
0 commit comments