Scribe logoScribeNotes & practice
Sign inStart free
  1. Notes
  2. ›IB Computer Science
  3. ›A1 Computer fundamentals
  4. ›A1.2 Data representation and logic

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.

  • 4 min read
  • 5 parts
  • 10 questions
  • Draft
Start a Quick 5 on this topic→Jump to the 10 questions
1/5Computers store all data as patterns of bits
  1. 1Computers store all data as patterns of bits
  2. 2Each binary place value is a power of two
  3. 3Hexadecimal gives a shorter way to write binary
  4. 4Logic gates combine binary inputs into one output
  5. 5Circuit diagrams are solved one gate at a time
  6. Check your recall
  7. Practice: 10 questions
1

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, nnn bits can hold 2n2^n2n different patterns, so a byte holds 28=2562^8=25628=256.

Text works the same way, because a code gives each character a number. In ASCII, the capital letter A has the code 65.

Common mistake

Binary is not a different kind of number. It is a different way of writing the same number.

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 1 done

2

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

Write the decimal number 45 as an 8-bit binary number.
  1. 1
    List the place values: 128, 64, 32, 16, 8, 4, 2, 1.
  2. 2
    128 and 64 are too large, so those places hold 0.
  3. 3
    45−32=1345-32=1345−32=13, so the 32 place holds 1. The 16 place holds 0.
  4. 4
    13−8=513-8=513−8=5, so the 8 place holds 1. Then 5−4=15-4=15−4=1, so the 4 place holds 1.
  5. 5
    The 2 place holds 0, and the 1 place holds 1.
  6. 6
    Check: 32+8+4+1=4532+8+4+1=4532+8+4+1=45.

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.

Part 2 done

Quick check

One question on the part you just read

Easy

How many different patterns can one byte hold?
Show answer and explanation

Answer: C · Worked explanation

A byte has eight bits, and nnn bits hold 2n2^n2n patterns, so a byte holds 28=2562^8=25628=256 patterns. The number 8 is the count of bits, not of patterns. The value 128 is only the largest place value in a byte, and 16 is far too small.
3

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

DecimalBinaryHexadecimal
101010A
111011B
121100C
131101D
141110E
151111F
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

Convert the binary number 10110110 to hexadecimal. Then find its decimal value.
  1. 1
    Split into groups of four: 1011 and 0110.
  2. 2
    1011 is 11, which is B. 0110 is 6.
  3. 3
    So the hexadecimal number is B6.
  4. 4
    Decimal: 11×16+6=176+6=18211\times16+6=176+6=18211×16+6=176+6=182.

Answer: The binary number 10110110 is B6 in hexadecimal and 182 in decimal.

Common mistake

Hexadecimal does not use fewer bits. B6 and 10110110 are the same eight bits, written in two ways.

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 3 done

4

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

ABA AND BA OR B
0000
0101
1001
1111
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

Exam tip

List inputs in counting order, 00, 01, 10, 11, so that no combination is missed.

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.

Part 4 done

Quick check

One question on the part you just read

Easy

Identify the digits that a hexadecimal number can use.
Show answer and explanation

Answer: D · Worked explanation

Hexadecimal has 16 values, so it needs the digits 0 to 9 and then the letters A to F, where F stands for 15. Using only 0 and 1 describes binary, and 0 to 9 gives only ten values. Stopping at H would give 18 values, which is too many.
5

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.

Figure 1. Wires carry values from left to right, and each gate uses the values that arrive at its inputs.

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.

Note read

Check your recall[14 marks]

6 written questions. Answer each one in your head or on paper, then open the mark scheme.

  1. 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 128+64+8+2=202128+64+8+2=202128+64+8+2=202.

    • 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. 2.Determine[3 marks]

    Determine the hexadecimal value of the decimal number 100.

    Show mark schemeHide mark scheme

    Model answer

    100=64+32+4100=64+32+4100=64+32+4, 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. 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. 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. 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. 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.

3.

Easy·State[1 mark]

State what a NOT gate does to its input.
Show answer and explanation

Answer: A · Worked explanation

A NOT gate has one input and reverses it, so 1 becomes 0 and 0 becomes 1. Outputting 1 only when all inputs are 1 describes AND, and outputting 1 when inputs differ describes XOR. Copying the input would not change the value at all.
4.

Medium·Calculate[1 mark]

Calculate the decimal value of the binary number 01001101.
Show answer and explanation

Answer: B · Worked explanation

The places holding 1 are 64, 8, 4 and 1, so 64+8+4+1=7764+8+4+1=7764+8+4+1=77. The value 178 comes from reading the bits in reverse order, as 10110010. The value 4 only counts the number of 1s, and 141 would be the value of 10001101.
5.

Medium·Determine[1 mark]

Determine the hexadecimal value of the binary number 11110001.
Show answer and explanation

Answer: B · Worked explanation

Split the bits into groups of four: 1111 and 0001. The first group is 15, which is F, and the second is 1, so the result is F1. Writing 1F reverses the groups. The value E1 would need the first group to be 1110, and 151 is not a valid way to write the two digits.
6.

Medium·Calculate[1 mark]

Calculate the 8-bit binary form of the decimal number 58.
Show answer and explanation

Answer: C · Worked explanation

Subtract place values: 58−32=2658-32=2658−32=26, 26−16=1026-16=1026−16=10, 10−8=210-8=210−8=2, and 2−2=02-2=02−2=0. The 32, 16, 8 and 2 places hold 1, giving 00111010. The pattern 00110110 is 54, 01011010 is 90 and 00101110 is 46, so each fails the check by addition.
7.

Medium·Identify[1 mark]

Identify the single gate that gives output 0 for inputs A = 1 and B = 0, and output 1 for inputs A = 0 and B = 0.
Show answer and explanation

Answer: D · Worked explanation

NOR gives the opposite of OR. For 1 and 0, OR gives 1 so NOR gives 0. For 0 and 0, OR gives 0 so NOR gives 1. AND gives 0 for 0 and 0, OR gives 0 for 0 and 0, and XOR gives 1 for 1 and 0, so each fails one of the conditions.
8.

Hard·Determine[2 marks]

A circuit has three gates. An AND gate takes A and B. A NOT gate takes C. An OR gate joins their outputs. A = 1, B = 0, C = 1. Determine the values at the AND gate, the NOT gate and the OR gate in that order.
Show answer and explanation

Answer: A · Worked explanation

AND of 1 and 0 gives 0. NOT of 1 gives 0. OR of 0 and 0 gives 0. The sequence 0, 1, 1 comes from forgetting to apply the NOT gate, and 1, 0, 1 comes from treating the AND gate as an OR gate.
9.

Hard·Determine[2 marks]

A 24-bit colour value is written in hexadecimal. Determine how many hex digits it needs.
Show answer and explanation

Answer: A · Worked explanation

One hex digit stands for exactly four bits, so 24 bits need 244=6\frac{24}{4}=6424​=6 digits. The answer 3 comes from dividing by 8, which counts bytes instead of hex digits. The answers 4 and 8 do not divide 24 bits into groups of four.
10.

Hard·Determine[2 marks]

Whole numbers from 0 to 100 must each be stored as a binary pattern. Determine the smallest number of bits that can do this.
Show answer and explanation

Answer: C · Worked explanation

The numbers 0 to 100 need 101 different patterns. Six bits give 26=642^6=6426=64 patterns, which is too few, and seven bits give 27=1282^7=12827=128, which is enough. Eight bits would also work, but it is a byte and not the smallest number, and five bits give only 32.

Keep going

Next topicA1.3 Operating and control systemsPrevious topicA1.1 Computer hardware and operation

More in A1 · Computer fundamentals

  1. A1.1Computer hardware and operationNotes · 10 questions
  2. A1.2Data representation and logicNotes · 10 questions
  3. A1.3Operating and control systemsNotes · 10 questions
  4. A1.4TranslationNotes · 10 questions· HL only

All IB Computer Science topics →

Draft: written by Scribe and checked automatically, not yet by a subject reviewer.

Practice questions are original, written by Scribe and checked automatically for correctness.

Topic codes follow the official numbering. Not endorsed by IB Diploma Programme or any exam board.

On this page

0/5 read

  1. 1Computers store all data as patterns of bits
  2. 2Each binary place value is a power of two
  3. 3Hexadecimal gives a shorter way to write binary
  4. 4Logic gates combine binary inputs into one output
  5. 5Circuit diagrams are solved one gate at a time
  6. Check your recall
  7. Practice: 10 questions
All coursesScribeHow it worksPricingPrivacyTerms

Notes and questions are written by Scribe in our own words. Topic codes follow the official course numbering so you can find your place. Not produced or endorsed by the IB, College Board, AQA, OCR, Pearson Edexcel or any exam board.

© 2026 Scribe