- Subjects
- Computer Science
- Question bank
- A1.2 Data representation and computer logic
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.
| Paper | SL and HL | HL only | All |
|---|---|---|---|
| Paper 1 | 91 | 1 | 92 |
| Paper 2 | 2 | 1 | 3 |
| Every paper | 93 | 2 | 95 |
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.
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.
- (a)
The latest wind speed reading is
1011 0110. State this value in decimal.1 mark
- (b)
The latest humidity reading is 203 in decimal. State this value in hexadecimal.
1 mark
- (c)
State the largest value that one reading can hold.
1 mark
- (d)
Outline one reason why the station's engineers display readings in hexadecimal rather than binary when testing the equipment.
2 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.

- (a)
Copy and complete the trace table for the input n = 13.
n
r
bits
output
13
(empty)
4 marks
- (b)
State the output when n = 32.
1 mark
- (c)
Explain why the output is incorrect when n = 0, and suggest how the flowchart could be corrected.
3 marks
- (d)
Outline how the flowchart could be changed so that it outputs the hexadecimal representation of n instead.
3 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.
- (a)
State the number of bits used to store the red component.
1 mark
- (b)
Convert the green component
8Bto decimal, showing your working.2 marks
- (c)
Convert the blue component
57to 8-bit binary.1 mark
- (d)
Calculate how many different colours can be represented with this 24-bit scheme.
2 marks
- (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
- (f)
Explain why the studio writes colours in hexadecimal rather than in binary or decimal.
3 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
def to_binary(n):
if n < 2:
return str(n)
return to_binary(n // 2) + str(n % 2)Java
public static String toBinary(int n) {
if (n < 2) {
return String.valueOf(n);
}
return toBinary(n / 2) + (n % 2);
}- (a)
State the base case of
to_binary/toBinary.1 mark
- (b)
Trace
to_binary(13)/toBinary(13), showing the argument of each call and the string returned by each call.4 marks
- (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
- (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 integern. For example,count_ones(13)returns 3. You must not use loops, strings or built-in conversion functions.4 marks
- (e)
State, with a reason, the number of recursive calls
to_binarymakes in terms of n, using Big O notation.2 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.
- (a)
Convert
3F2Ato binary.2 marks
- (b)
Convert
3F2Ato decimal, showing your working.2 marks
- (c)
State the number of different visitor numbers that can be stored in 16 bits.
1 mark
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.
- (a)
State the remainders, in the order they are produced, when 13 is converted.
1 mark
- (b)
Construct a function / method
to_binary(n)/toBinary(n)that uses a stack to return the binary form of the non-negative integernas a string. For example,to_binary(13)returns"1101"andto_binary(0)returns"0". You must not usebin()(Python) orInteger.toBinaryString(Java).5 marks
- (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.
More questions in Computer fundamentals
- A1.1Computer hardware and operation
- A1.2Data representation and computer logicThis page
- A1.3Operating systems and control systems
- A1.4TranslationHL only
More on Data representation and computer logic
- A1.2 Data representation and computer logic notesWhat Data representation and computer logic covers, explained, with its key terms.
- IB Computer Science question bankEvery Computer Science topic counted, and one question from each with its markscheme.
- Computer Science exam formatEach Computer Science paper, how long it is and its share of the grade.
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.