Flashcards

1.4.1 Data types

Card 1 of 21

  1. Question

    Name the five primitive data types in the OCR specification.

    Answer

    Integer, real (floating point), character, string and Boolean.

  2. Question

    Why should a phone number be stored as a string rather than an integer?

    Answer

    It may start with 0 or contain spaces, which an integer would lose, and it is never used in calculations.

  3. Question

    What range of values can 8 bits hold as unsigned binary?

    Answer

    0 to 255. In general, n bits hold 0 to 2n − 1.

  4. Question

    Convert 0101 1010 to denary.

    Answer

    64 + 16 + 8 + 2 = 90.

  5. Question

    Why is hexadecimal used?

    Answer

    Each hex digit stands for 4 bits, so it is a shorter way to write binary that is easier for people to read and remember, with fewer mistakes.

  6. Question

    Convert 3C (hexadecimal) to denary.

    Answer

    3 × 16 + 12 = 60.

  7. Question

    How do you convert binary to hexadecimal?

    Answer

    Split the bits into groups of 4 from the right, then write each group as one hex digit. 0101 1010 is 5A.

  8. Question

    How is a negative number stored in sign and magnitude?

    Answer

    The most significant bit is the sign (1 for negative) and the remaining bits hold the size. −90 is 1101 1010.

  9. Question

    How do you write a negative denary number in two's complement?

    Answer

    Write the positive number in binary, flip every bit, then add 1. −90: 0101 1010 → 1010 0101 → 1010 0110.

  10. Question

    What range can an 8-bit two's complement number hold?

    Answer

    −128 to 127. The most significant bit has place value −128.

  11. Question

    Give two advantages of two's complement over sign and magnitude.

    Answer

    Binary addition and subtraction work directly, so no extra hardware is needed. There is only one representation of zero, so it holds one more number (−128).

  12. Question

    How do you subtract one binary number from another?

    Answer

    Add the two's complement of the second number, and ignore any carry out of the most significant bit.

  13. Question

    What is overflow?

    Answer

    When the result of a calculation is too large to fit in the number of bits available, so the stored result is wrong.

  14. Question

    In floating point, what are the mantissa and the exponent?

    Answer

    The mantissa holds the significant digits of the number. The exponent says how many places to move the binary point: value = mantissa × 2exponent.

  15. Question

    What is the effect of giving more bits to the mantissa, and to the exponent?

    Answer

    More mantissa bits give more precision. More exponent bits give a greater range.

  16. Question

    How can you tell whether a floating point number is normalised?

    Answer

    The first two bits of the mantissa are different: 01 for a positive number, 10 for a negative number.

  17. Question

    Why are floating point numbers normalised?

    Answer

    To store each number as precisely as possible in the bits available, and so each value has only one representation.

  18. Question

    List the steps to add two floating point numbers.

    Answer

    Make the exponents the same (shift right the mantissa of the number with the smaller exponent), add the mantissas (to subtract, add the two's complement), then normalise the result.

  19. Question

    What is the difference between a logical shift right and an arithmetic shift right?

    Answer

    A logical shift fills the gap with 0. An arithmetic shift copies the sign bit, so a two's complement number keeps its sign and is divided by 2.

  20. Question

    What do AND, OR and XOR masks do?

    Answer

    An AND mask keeps the bits where the mask is 1 and clears the rest. An OR mask sets bits to 1. An XOR mask flips the bits where the mask is 1.

  21. Question

    Compare ASCII and Unicode.

    Answer

    ASCII uses 7 bits for 128 characters, mostly English. Unicode uses up to 32 bits per character, enough for every writing system and emoji, and its first 128 codes match ASCII.

Keys: Space flips, ← → move between cards.

Tap the card to flip it. Swipe to change card.