Quiz

1.4.1 Data types

  1. Which data type is most suitable for storing a phone number such as 07700 900123?

    1. String
    2. Integer
    3. Real
    4. Boolean
    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.

  2. What is the hexadecimal value of the binary number 1011 0110?

    1. B6
    2. 6B
    3. 116
    4. 182
    Show answer

    Answer: B6

    Split into nibbles from the right: 1011 is 11, which is B, and 0110 is 6, giving B6. 182 is the denary value, not the hexadecimal.

  3. What is 2F (hexadecimal) in denary?

    1. 47
    2. 32
    3. 215
    4. 17
    Show answer

    Answer: 47

    The first digit is worth 16s and F is 15, so 2 × 16 + 15 = 47.

  4. What is −20 as an 8-bit two's complement binary number?

    1. 1110 1100
    2. 1001 0100
    3. 1110 1011
    4. 0001 0100
    Show answer

    Answer: 1110 1100

    +20 is 0001 0100. Flipping every bit gives 1110 1011, and adding 1 gives 1110 1100. Check: −128 + 64 + 32 + 8 + 4 = −20. 1001 0100 is −20 in sign and magnitude, and 1110 1011 forgets to add 1.

  5. What is the range of an 8-bit two's complement integer?

    1. −128 to 127
    2. −127 to 127
    3. 0 to 255
    4. −128 to 128
    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.

  6. Two unsigned 8-bit numbers, 1100 0000 and 0101 0000, are added. What happens?

    1. Overflow: the answer needs 9 bits
    2. The answer is 0001 0000 with no problem
    3. Underflow: the answer is too small
    4. The answer is negative
    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.

  7. A floating point number has an 8-bit mantissa 0101 0000 and a 4-bit exponent 0010, both in two's complement. What is its denary value?

    1. 2.5
    2. 5
    3. 0.625
    4. 1.25
    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.

  8. Which of these 8-bit mantissas is normalised?

    1. 1011 0000
    2. 0011 0000
    3. 1101 0000
    4. 0001 0000
    Show answer

    Answer: 1011 0000

    A normalised mantissa starts with two different bits: 01 if positive or 10 if negative. 1011 0000 starts 10, so it is a normalised negative number. Mantissas starting 00 or 11 can be shifted left to gain precision.

  9. Normalise the mantissa 0001 1000 with exponent 0110.

    1. Mantissa 0110 0000, exponent 0100
    2. Mantissa 0110 0000, exponent 1000
    3. Mantissa 0000 0110, exponent 1000
    4. Mantissa 0110 0000, exponent 0110
    Show answer

    Answer: Mantissa 0110 0000, exponent 0100

    Shift 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 is 0100.

  10. When adding two floating point numbers, what must be done before the mantissas are added?

    1. Make the exponents the same
    2. Normalise both mantissas
    3. Add the exponents together
    4. Convert both numbers to sign and magnitude
    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.

  11. Which mask and operator set the most significant bit of a byte to 1 and leave every other bit unchanged?

    1. OR with 1000 0000
    2. AND with 1000 0000
    3. XOR with 1000 0000
    4. AND with 0111 1111
    Show answer

    Answer: OR with 1000 0000

    OR with 1 always gives 1, and OR with 0 leaves a bit as it was, so 1000 0000 sets just the MSB. AND with 1000 0000 would clear the other bits, and XOR would flip the MSB rather than always setting it.

  12. The byte 0000 1100 (12) has a logical shift left by 2 places. What is the result?

    1. 0011 0000 (48)
    2. 0000 0011 (3)
    3. 0000 1100 (12)
    4. 0001 1000 (24)
    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.

  13. Why was Unicode introduced when ASCII already existed?

    1. ASCII's 128 codes cannot represent the characters of most of the world's languages
    2. ASCII cannot represent digits
    3. Unicode always uses less storage than ASCII
    4. ASCII cannot be stored in binary
    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.

  14. What is the denary number 77 as an 8-bit binary number?

    1. 0100 1101
    2. 0100 1110
    3. 1011 0010
    4. 0100 1011
    Show answer

    Answer: 0100 1101

    77 = 64 + 8 + 4 + 1, so there are 1s in the 64, 8, 4 and 1 columns: 0100 1101. 0100 1110 is 78 and 0100 1011 is 75.

  15. What is the denary number 200 in hexadecimal?

    1. C8
    2. 8C
    3. 128
    4. C80
    Show answer

    Answer: C8

    200 = 12 × 16 + 8. Twelve is C, so the answer is C8. In binary, 200 is 1100 1000, and the two nibbles are C and 8. 8C has the digits the wrong way round.

  16. 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?

    1. 1110 0111
    2. 1001 1001
    3. 0001 1001
    4. 1110 0110
    Show answer

    Answer: 1110 0111

    75 is 0100 1011. Flipping the bits and adding 1 gives 1011 0101 (−75). 0011 0010 + 1011 0101 = 1110 0111, which is −128 + 64 + 32 + 4 + 2 + 1 = −25. 1001 1001 is −25 in sign and magnitude, and 1110 0110 comes from forgetting to add 1.

  17. Add 2.5 (mantissa 0101 0000, exponent 0010) and 0.75 (mantissa 0110 0000, exponent 0000). Both use two's complement. What is the result?

    1. Mantissa 0110 1000, exponent 0010
    2. Mantissa 0110 1000, exponent 0000
    3. Mantissa 1011 0000, exponent 0010
    4. Mantissa 0110 1000, exponent 0100
    Show answer

    Answer: Mantissa 0110 1000, exponent 0010

    Line up the exponents first: 0.75 has the smaller exponent, so shift its mantissa right 2 places to 0001 1000 with exponent 2. Adding gives 0110 1000, exponent 2, which is 0.8125 × 4 = 3.25. Adding the mantissas without lining them up gives 1011 0000, which would be a negative number.