Quiz
1.4.1 Data types
-
Which data type is most suitable for storing a phone number such as
07700 900123?Show answer
Answer: String
A phone number can start with 0 and contain a space, and nobody does arithmetic with it, so it is text: a string. Storing it as an integer would drop the leading 0.
-
What is the hexadecimal value of the binary number
1011 0110?Show answer
Answer:
B6Split into nibbles from the right:
1011is 11, which is B, and0110is 6, givingB6. 182 is the denary value, not the hexadecimal. -
What is
2F(hexadecimal) in denary?Show answer
Answer: 47
The first digit is worth 16s and F is 15, so 2 × 16 + 15 = 47.
-
What is −20 as an 8-bit two's complement binary number?
Show answer
Answer:
1110 1100+20 is
0001 0100. Flipping every bit gives1110 1011, and adding 1 gives1110 1100. Check: −128 + 64 + 32 + 8 + 4 = −20.1001 0100is −20 in sign and magnitude, and1110 1011forgets to add 1. -
What is the range of an 8-bit two's complement integer?
Show answer
Answer: −128 to 127
The most significant bit is worth −128 and the other seven bits add up to at most 127, so the range is −128 to 127. −127 to 127 is the range of sign and magnitude, which wastes a pattern on a second zero.
-
Two unsigned 8-bit numbers,
1100 0000and0101 0000, are added. What happens?Show answer
Answer: Overflow: the answer needs 9 bits
192 + 80 = 272, which is more than 255, the largest number 8 bits can hold. A carry goes out of the most significant bit, so the result overflows; the 8 bits left (
0001 0000) do not hold the right answer. -
A floating point number has an 8-bit mantissa
0101 0000and a 4-bit exponent0010, both in two's complement. What is its denary value?Show answer
Answer: 2.5
The mantissa is
0.1010000, which is 0.625. The exponent is 2, so move the binary point 2 places right:10.1, which is 2.5. -
Which of these 8-bit mantissas is normalised?
Show answer
Answer:
1011 0000A normalised mantissa starts with two different bits:
01if positive or10if negative.1011 0000starts10, so it is a normalised negative number. Mantissas starting00or11can be shifted left to gain precision. -
Normalise the mantissa
0001 1000with exponent0110.Show answer
Answer: Mantissa
0110 0000, exponent0100Shift the mantissa left 2 places so it starts
01:0110 0000. Moving the binary point 2 places right makes the number 4 times bigger, so take 2 off the exponent to keep the same value: 6 − 2 = 4, which is0100. -
When adding two floating point numbers, what must be done before the mantissas are added?
Show answer
Answer: Make the exponents the same
Mantissas can only be added when their binary points line up, which means the exponents must match. Shift right the mantissa of the number with the smaller exponent, increasing that exponent until they are equal. Normalisation comes last, on the result.
-
Which mask and operator set the most significant bit of a byte to 1 and leave every other bit unchanged?
Show answer
Answer: OR with
1000 0000OR with 1 always gives 1, and OR with 0 leaves a bit as it was, so
1000 0000sets just the MSB. AND with1000 0000would clear the other bits, and XOR would flip the MSB rather than always setting it. -
The byte
0000 1100(12) has a logical shift left by 2 places. What is the result?Show answer
Answer:
0011 0000(48)Each bit moves 2 places left and 0s fill the gap on the right, giving
0011 0000. Each place left doubles an unsigned number, so 2 places multiply by 4: 12 × 4 = 48. -
Why was Unicode introduced when ASCII already existed?
Show answer
Answer: ASCII's 128 codes cannot represent the characters of most of the world's languages
With 7 bits, ASCII has room for only 128 characters, enough for English but not for other alphabets and symbols. Unicode uses more bits per character, so it can represent over a million characters. It often uses more storage, not less.
-
What is the denary number 77 as an 8-bit binary number?
Show answer
Answer:
0100 110177 = 64 + 8 + 4 + 1, so there are 1s in the 64, 8, 4 and 1 columns:
0100 1101.0100 1110is 78 and0100 1011is 75. -
What is the denary number 200 in hexadecimal?
Show answer
Answer:
C8200 = 12 × 16 + 8. Twelve is C, so the answer is
C8. In binary, 200 is1100 1000, and the two nibbles are C and 8.8Chas the digits the wrong way round. -
In 8-bit two's complement, 50 − 75 is worked out by adding
0011 0010(50) and the two's complement of 75. What is the result?Show answer
Answer:
1110 011175 is
0100 1011. Flipping the bits and adding 1 gives1011 0101(−75).0011 0010+1011 0101=1110 0111, which is −128 + 64 + 32 + 4 + 2 + 1 = −25.1001 1001is −25 in sign and magnitude, and1110 0110comes from forgetting to add 1. -
Add 2.5 (mantissa
0101 0000, exponent0010) and 0.75 (mantissa0110 0000, exponent0000). Both use two's complement. What is the result?Show answer
Answer: Mantissa
0110 1000, exponent0010Line up the exponents first: 0.75 has the smaller exponent, so shift its mantissa right 2 places to
0001 1000with exponent 2. Adding gives0110 1000, exponent 2, which is 0.8125 × 4 = 3.25. Adding the mantissas without lining them up gives1011 0000, which would be a negative number.