IB Computer Science · A1 · Computer fundamentals
A1.2 Data representation and logic
Explain how data is stored as bits, convert numbers between binary, decimal and hexadecimal, and interpret simple logic gate circuits.
1/5Computers store all data as patterns of bits
Part 1 of 5: Computers store all data as patterns of bits
A computer circuit is built from switches that are either on or off. Two states are easy to make reliable. We write them as 1 and 0.
A bit is one such value. A group of bits can stand for a number, a letter, a colour or a sound sample. The binary system writes numbers using only the digits 0 and 1.
Eight bits form a byte. In general, bits can hold different patterns, so a byte holds .
Text works the same way, because a code gives each character a number. In ASCII, the capital letter A has the code 65.
Key terms · tap one for its definition
bit
A bit is a binary digit, the smallest unit of data, which has a value of either 0 or 1.
binary
Binary is a base-2 number system that uses only the digits 0 and 1.
byte
A byte is a group of eight bits, which can hold 256 different values.
Part 2 of 5: Each binary place value is a power of two
Now that data is stored as bits, we need a way to read a binary number. In decimal, each place value is ten times the one to its right. In binary, each is twice the one to its right.
The place values in a byte are 128, 64, 32, 16, 8, 4, 2 and 1. To convert binary to decimal, add the place values that hold a 1. To convert decimal to binary, subtract the largest place value that fits and repeat.
Worked example
Convert a decimal number to binary
- List the place values: 128, 64, 32, 16, 8, 4, 2, 1.
- 128 and 64 are too large, so those places hold 0.
- , so the 32 place holds 1. The 16 place holds 0.
- , so the 8 place holds 1. Then , so the 4 place holds 1.
- The 2 place holds 0, and the 1 place holds 1.
- Check: .
Answer: The 8-bit binary number is 00101101.
Key term
place value
A place value is the amount a digit is worth because of its position in a number.

Quick check
One question on the part you just read
Easy
Show answer and explanation
Answer: C · Worked explanation
Part 3 of 5: Hexadecimal gives a shorter way to write binary
Long strings of bits are hard to read, so programmers use a shorter form. The hexadecimal system is base 16. It uses the digits 0 to 9 and the letters A to F.
In hexadecimal, A stands for 10 and F stands for 15. One hex digit stands for exactly four bits.
Values 10 to 15 in three number systems
- Decimal
- 10
- Binary
- 1010
- Hexadecimal
- A
- Decimal
- 11
- Binary
- 1011
- Hexadecimal
- B
- Decimal
- 12
- Binary
- 1100
- Hexadecimal
- C
- Decimal
- 13
- Binary
- 1101
- Hexadecimal
- D
- Decimal
- 14
- Binary
- 1110
- Hexadecimal
- E
- Decimal
- 15
- Binary
- 1111
- Hexadecimal
- F
To convert binary to hexadecimal, split the bits into groups of four, starting from the right. Replace each group with its hex digit.
Worked example
Convert binary to hexadecimal and decimal
- Split into groups of four: 1011 and 0110.
- 1011 is 11, which is B. 0110 is 6.
- So the hexadecimal number is B6.
- Decimal: .
Answer: The binary number 10110110 is B6 in hexadecimal and 182 in decimal.
Key term
hexadecimal
Hexadecimal is a base-16 number system using the digits 0 to 9 and A to F, where A to F mean 10 to 15.
Part 4 of 5: Logic gates combine binary inputs into one output
Bits are not only stored. Circuits also make decisions with them. A logic gate is a circuit with one or more binary inputs and one binary output. A truth table lists every input combination and the output it gives.
An AND gate outputs 1 only when all its inputs are 1. An OR gate outputs 1 when at least one input is 1. A NOT gate has one input and reverses it.
Truth table for AND and OR with inputs A and B
- A
- 0
- B
- 0
- A AND B
- 0
- A OR B
- 0
- A
- 0
- B
- 1
- A AND B
- 0
- A OR B
- 1
- A
- 1
- B
- 0
- A AND B
- 0
- A OR B
- 1
- A
- 1
- B
- 1
- A AND B
- 1
- A OR B
- 1
Key terms · tap one for its definition
logic gate
A logic gate is an electronic circuit that applies a logical operation to one or more binary inputs to give one binary output.
truth table
A truth table is a table listing every combination of inputs to a logic gate or circuit with the output each produces.

Quick check
One question on the part you just read
Easy
Show answer and explanation
Answer: D · Worked explanation
Part 5 of 5: Circuit diagrams are solved one gate at a time
Real circuits join several gates, so the order of working matters. Wires carry values from left to right. Work out the first gates, then feed their outputs into the next gate.
Writing the value on each wire as you go prevents slips. Then test one more input combination to confirm that your working holds. Three more gates are common. NAND gives the opposite of AND, and NOR gives the opposite of OR. XOR outputs 1 only when its two inputs differ.
Check your recall[14 marks]
6 written questions. Answer each one in your head or on paper, then open the mark scheme.
- 1.Calculate[3 marks]
Calculate the decimal value of the binary number 11001010.
Show mark schemeHide mark scheme
Model answer
The places holding 1 are 128, 64, 8 and 2. Adding them gives .
- 1 mark for identifying the place values 128, 64, 8 and 2 as holding a 1
- 1 mark for adding the place values
- 1 mark for obtaining 202
- 2.Determine[3 marks]
Determine the hexadecimal value of the decimal number 100.
Show mark schemeHide mark scheme
Model answer
, so the binary number is 01100100. The groups 0110 and 0100 are 6 and 4, so the hexadecimal value is 64.
- 1 mark for converting 100 to the binary number 01100100
- 1 mark for splitting the bits into groups of four, 0110 and 0100
- 1 mark for giving the answer 64 (or dividing by 16 to get 6 remainder 4)
- 3.Outline[2 marks]
Outline why computers store data in binary.
Show mark schemeHide mark scheme
Model answer
Computer circuits are built from switches that are either on or off. Two states are easy to make reliable, and they are written as 1 and 0.
- 1 mark for stating that circuits are built from switches with two states, on and off
- 1 mark for stating that two states are easy to make reliable or that they are written as 1 and 0
- 4.Deduce[2 marks]
Deduce the output of a NAND gate when both inputs are 1. Show the output of the AND gate first.
Show mark schemeHide mark scheme
Model answer
An AND gate with inputs 1 and 1 outputs 1. A NAND gate gives the opposite, so its output is 0.
- 1 mark for stating that the AND output is 1
- 1 mark for stating that the NAND output is the opposite, 0
- 5.Explain[2 marks]
Explain why programmers often write binary values in hexadecimal.
Show mark schemeHide mark scheme
Model answer
One hex digit stands for exactly four bits. A long binary value therefore becomes a much shorter, easier-to-read hexadecimal value.
- 1 mark for stating that one hex digit represents four bits
- 1 mark for explaining that the value is shorter and easier to read or convert
- 6.Describe[2 marks]
Describe the output of an XOR gate for all four input combinations.
Show mark schemeHide mark scheme
Model answer
An XOR gate outputs 1 when its inputs differ, which is for 01 and 10. It outputs 0 when its inputs are the same, which is for 00 and 11.
- 1 mark for stating that the output is 1 for 01 and 10, when the inputs differ
- 1 mark for stating that the output is 0 for 00 and 11, when the inputs are the same

Practice this topic
10 quick-fire multiple-choice questions, easy to hard. Tap an answer to see if you're right and the worked explanation. (The written questions with mark schemes are under “Check your recall” above.)
0 right0 of 10 answered
Includes the 2 quick checks in the note above.
EasyState[1 mark]
Show answer and explanation
Answer: A · Worked explanation
MediumCalculate[1 mark]
Show answer and explanation
Answer: B · Worked explanation
MediumDetermine[1 mark]
Show answer and explanation
Answer: B · Worked explanation
MediumCalculate[1 mark]
Show answer and explanation
Answer: C · Worked explanation
MediumIdentify[1 mark]
Show answer and explanation
Answer: D · Worked explanation
HardDetermine[2 marks]
Show answer and explanation
Answer: A · Worked explanation
HardDetermine[2 marks]
Show answer and explanation
Answer: A · Worked explanation
HardDetermine[2 marks]
Show answer and explanation
Answer: C · Worked explanation