A1.2 Data representation and computer logic questions for IB Computer Science

95 questions on Data representation and computer logic, written by Augment in the style of IB exam papers. Six of them are below in full, to answer on paper.

  • IB Computer Science
  • Part of A1 Computer fundamentals
  • SL and HL

Questions by paper and level

SL and HL questions are for students at either level. HL only questions cover what only HL students study.

PaperSL and HLHL onlyAll
Paper 191192
Paper 2213
Every paper93295

Counted on

Questions to try

Written by Augment in the style of IB exams, not past papers. Answer them on paper, then check each one against its markscheme with a free account.

Question 1 · CS-00071Paper 1 · 5 marks

A coastal weather station measures wind speed and humidity. Each reading is stored as an 8-bit unsigned binary integer before it is sent to a central server.

  1. (a)

    The latest wind speed reading is 1011 0110. State this value in decimal.

    1 mark

  2. (b)

    The latest humidity reading is 203 in decimal. State this value in hexadecimal.

    1 mark

  3. (c)

    State the largest value that one reading can hold.

    1 mark

  4. (d)

    Outline one reason why the station's engineers display readings in hexadecimal rather than binary when testing the equipment.

    2 marks

Question 2 · CS-01227Paper 2 · 11 marks

A firmware tool shows the binary pattern of whole numbers. The algorithm it uses is shown in Figure 1. DIV gives the whole-number part of a division and MOD gives the remainder. bits holds a string of characters, which starts empty.

Flowchart: Start; Input n; bits ← "" (empty); loop while n > 0: r ← n MOD 2; put r in front of bits; n ← n DIV 2; back to the test. When n > 0 is false: Output bits; End.
Figure 1
  1. (a)

    Copy and complete the trace table for the input n = 13.

    n

    r

    bits

    output

    13

    (empty)

    4 marks

  2. (b)

    State the output when n = 32.

    1 mark

  3. (c)

    Explain why the output is incorrect when n = 0, and suggest how the flowchart could be corrected.

    3 marks

  4. (d)

    Outline how the flowchart could be changed so that it outputs the hexadecimal representation of n instead.

    3 marks

Question 3 · CS-00072Paper 1 · 11 marks

A web design studio stores each colour on its clients' websites as a 24-bit RGB value: one byte each for red, green and blue. Colours are written as six hexadecimal digits; for example, the studio's sea green is #2E8B57, where 2E is red, 8B is green and 57 is blue.

  1. (a)

    State the number of bits used to store the red component.

    1 mark

  2. (b)

    Convert the green component 8B to decimal, showing your working.

    2 marks

  3. (c)

    Convert the blue component 57 to 8-bit binary.

    1 mark

  4. (d)

    Calculate how many different colours can be represented with this 24-bit scheme.

    2 marks

  5. (e)

    A client wants a colour with red = 200, green = 16 and blue = 255 (all decimal). Construct the six-digit hexadecimal code for this colour.

    2 marks

  6. (f)

    Explain why the studio writes colours in hexadecimal rather than in binary or decimal.

    3 marks

Question 4 · CS-01320Paper 2 · HL only · 14 marks

Students in a networking class convert decimal values to binary. Their teacher shows them the recursive function/method to_binary / toBinary, which returns the binary digits of a non-negative integer as a string.

Python

Python
def to_binary(n):
    if n < 2:
        return str(n)
    return to_binary(n // 2) + str(n % 2)

Java

Java
public static String toBinary(int n) {
    if (n < 2) {
        return String.valueOf(n);
    }
    return toBinary(n / 2) + (n % 2);
}
  1. (a)

    State the base case of to_binary / toBinary.

    1 mark

  2. (b)

    Trace to_binary(13) / toBinary(13), showing the argument of each call and the string returned by each call.

    4 marks

  3. (c)

    The least significant bit (n % 2) is worked out first, but it appears last in the result. Explain how the order of the operations in the recursive case produces the digits in the correct order.

    3 marks

  4. (d)

    Construct, in Python or Java, a recursive function/method count_ones(n) / countOnes(n) that returns the number of 1 bits in the binary form of a non-negative integer n. For example, count_ones(13) returns 3. You must not use loops, strings or built-in conversion functions.

    4 marks

  5. (e)

    State, with a reason, the number of recursive calls to_binary makes in terms of n, using Big O notation.

    2 marks

Question 5 · CS-00073Paper 1 · 5 marks

A science museum prints a 16-bit visitor number on every annual pass. The number is shown on the pass in hexadecimal; one pass shows 3F2A.

  1. (a)

    Convert 3F2A to binary.

    2 marks

  2. (b)

    Convert 3F2A to decimal, showing your working.

    2 marks

  3. (c)

    State the number of different visitor numbers that can be stored in 16 bits.

    1 mark

Question 6 · CS-01476Paper 2 · 8 marks

A networking tutorial app shows students the binary form of numbers. To convert a positive integer to binary, the number is repeatedly divided by 2. The remainders give the binary digits, but they are produced in the reverse of the order in which they must be written.

Stack (Python) and IntStack (Java) have the methods push, pop, peek and is_empty / isEmpty.

  1. (a)

    State the remainders, in the order they are produced, when 13 is converted.

    1 mark

  2. (b)

    Construct a function / method to_binary(n) / toBinary(n) that uses a stack to return the binary form of the non-negative integer n as a string. For example, to_binary(13) returns "1101" and to_binary(0) returns "0". You must not use bin() (Python) or Integer.toBinaryString (Java).

    5 marks

  3. (c)

    Explain why a stack is appropriate for this conversion.

    2 marks

Practice all 95 in Augment

Free with an account. Every question has its markscheme, and Augment keeps the ones you got wrong so you can come back to them.

The notes on A1.2 Data representation and computer logic

More questions in Computer fundamentals

  1. A1.1Computer hardware and operation
  2. A1.2Data representation and computer logicThis page
  3. A1.3Operating systems and control systems
  4. A1.4TranslationHL only

Check your answers in Augment

A free account opens all 95 questions on Data representation and computer logic with their markschemes, and keeps a record of what you have marked.