IB Computer Science2027 syllabus
Level view
A1.2.1

Principal methods of representing data

SL & HL30 min readLesson

In one sentence: Computers store and process numbers in binary (base-2) because two electrical states are reliable in hardware, while programmers often convert those integers to decimal (base-10) for calculation or hexadecimal (base-16) for compact inspection.

What you will learn

By the end of this lesson, you should be able to:

  • Explain why digital computers use binary (base-2) and why hexadecimal (base-16) is useful to humans.
  • Represent positive integers in binary and hexadecimal.
  • Convert integers accurately between binary and decimal, hexadecimal and decimal, and binary and hexadecimal.

Before you begin

No prior number-system conversion experience is required. Subscripts are used where helpful to make the number base explicit: 1011_2 means binary (base-2), 11_10 means decimal (base-10), and 1F_16 means hexadecimal (base-16).

Key words

TermSimple meaning
Binary (base-2)A number system with two digits (0 and 1), where each place value is a power of 2.
Decimal (base-10)The everyday number system with ten digits (0–9), where each place value is a power of 10.
Hexadecimal (base-16)A base-16 number system using digits 0–9 and letters A–F (representing decimal 10–15).
BitA single binary digit (0 or 1).
NibbleA group of 4 bits (0000_2 to 1111_2), which corresponds directly to one hexadecimal digit.
ByteA group of 8 bits, capable of representing 256 distinct unsigned values (0 to 255).
Most significant bit (MSB)The leftmost bit in a binary integer, carrying the largest place value.
Least significant bit (LSB)The rightmost bit in a binary integer, carrying the smallest place value (1).
NoiseUnwanted electrical voltage or current fluctuations that can corrupt a signal.

The idea, step by step

Why computers use binary

Although early mechanical and experimental designs tested decimal (base-10), ternary (base-3), and quaternary (base-4) machines, modern digital computers standardize on binary (base-2):

  1. Hardware simplicity: Electronic circuits are built from billions of microscopic transistors acting as switches that are either off (0) or on (1). Detecting two distinct voltage levels requires far simpler circuitry than distinguishing ten separate voltage levels.
  2. Alignment with digital logic: Boolean algebra operates on two truth values (0/false and 1/true), allowing arithmetic and control circuits to be built directly from simple logic gates.
  3. Resilience to noise: Electrical signals degrade or pick up interference (noise). Keeping only two widely separated states (low voltage versus high voltage) makes errors much less likely when reading, storing, or transmitting data.

Bits, bytes, and storage units

Each column in a positional number system multiplies the column to its right by the base:

  • In decimal (base-10), place values from right to left are 1, 10, 100, 1,000 (10^0, 10^1, 10^2, 10^3).
  • In binary (base-2), place values from right to left double at each step: 1, 2, 4, 8, 16, 32, 64, 128 (2^0 through 2^7).

Computers commonly group 8 bits into 1 byte. If an integer needs fewer than 8 bits, leading 0s are padded on the left. An unsigned 8-bit byte has 2^8 = 256 distinct bit patterns, spanning decimal 0 (00000000_2) to 255 (11111111_2).

When measuring quantities of data, lowercase b denotes bits and uppercase B denotes bytes (1 B = 8 b). There are also two prefix standards:

  • Decimal (SI) prefixes use powers of 1,000: 1 KB = 1,000 B, 1 MB = 1,000 KB, 1 GB = 1,000 MB, 1 TB = 1,000 GB.
  • Binary (IEC) prefixes use powers of 1,024 (2^10): 1 KiB = 1,024 B, 1 MiB = 1,024 KiB, 1 GiB = 1,024 MiB, 1 TiB = 1,024 GiB.

Converting between binary and decimal

Binary to decimal

Two reliable methods convert an unsigned binary integer to decimal:

  1. Positional place-value method: Write the binary powers of 2 above each bit from right (1) to left, then add every place value that has a 1 underneath it.

    • Example: Convert 11010101_2 to decimal:
    1286432168421
    11010101

    128 + 64 + 16 + 4 + 1 = 213_10

  2. Doubling method: Start with 0 (or the leftmost 1) at the MSB, move left to right, and at each bit compute (current total × 2) + bit:

    • Using 11010101_2, the step-by-step totals are 0×2+1 = 1, 1×2+1 = 3, 3×2+0 = 6, 6×2+1 = 13, 13×2+0 = 26, 26×2+1 = 53, 53×2+0 = 106, and 106×2+1 = 213_10.

Decimal to binary

  1. Repeated division by 2: Divide the decimal number by 2 repeatedly, recording each quotient and remainder (0 or 1) until the quotient reaches 0. The first remainder is the LSB (rightmost bit), so read the remainders from last to first (bottom to top) and pad to 8 bits if needed.
    • Example: Convert 75_10 to binary:
      • 75 ÷ 2 = 37 remainder 1 (LSB)
      • 37 ÷ 2 = 18 remainder 1
      • 18 ÷ 2 = 9 remainder 0
      • 9 ÷ 2 = 4 remainder 1
      • 4 ÷ 2 = 2 remainder 0
      • 2 ÷ 2 = 1 remainder 0
      • 1 ÷ 2 = 0 remainder 1 (MSB)
      • Reading from last remainder to first gives 1001011_2, padded to 8 bits as 01001011_2.
  2. Place-value subtraction method: List 128, 64, 32, 16, 8, 4, 2, 1. Moving left to right, if the column value is less than or equal to the remaining number, write 1 and subtract it; otherwise write 0.
    • For 75_10: 128 > 75 (0), 64 ≤ 75 (1, remaining 11), 32 > 11 (0), 16 > 11 (0), 8 ≤ 11 (1, remaining 3), 4 > 3 (0), 2 ≤ 3 (1, remaining 1), 1 ≤ 1 (1, remaining 0), giving 01001011_2.

Hexadecimal (base-16) and why it is used

Long binary strings such as 1011011100101110_2 are hard for humans to read without making mistakes. Hexadecimal (base-16) solves this because every 4-bit nibble (0000_2 to 1111_2, representing 0 to 15) maps to exactly one hexadecimal digit (0–9, A–F). A single 8-bit byte therefore takes only two hex digits, making debugging output, memory dumps, memory addresses, and RGB colour values much more compact while keeping the link to binary clear.

DecimalHex4-bit binaryDecimalHex4-bit binary
000000881000
110001991001
22001010A1010
33001111B1011
44010012C1100
55010113D1101
66011014E1110
77011115F1111

Converting between binary and hexadecimal

  1. Binary to hexadecimal: Group the bits into 4-bit nibbles starting from the right (pad the leftmost group with 0s if needed), evaluate each 4-bit nibble (0–15), and write its hex symbol.
    • Example: Convert 10110111_2 to hexadecimal:
      • Split into nibbles: 1011 and 0111
      • Convert each nibble: 1011_2 = 8+2+1 = 11_10 = B_16; 0111_2 = 4+2+1 = 7_10 = 7_16
      • Result: B7_16.
  2. Hexadecimal to binary: Expand each hex digit individually into its full 4-bit binary nibble (keeping leading zeros inside each nibble), then join the nibbles.
    • Example: Convert D4_16 to binary:
      • D_16 = 13_10 = 1101_2 and 4_16 = 4_10 = 0100_2
      • Result: 11010100_2.

Converting between decimal and hexadecimal

  1. Decimal to hexadecimal: Divide repeatedly by 16 until the quotient is 0. Record each remainder (0–15), convert remainders 10–15 to A–F, and read the hex digits from last remainder to first (or alternatively convert decimal to 8-bit binary and then to two hex nibbles).
    • Example: Convert 219_10 to hexadecimal:
      • 219 ÷ 16 = 13 remainder 11 (11 = B)
      • 13 ÷ 16 = 0 remainder 13 (13 = D)
      • Reading last remainder to first gives DB_16.
  2. Hexadecimal to decimal: Convert each hex digit to its decimal value (0–15), multiply by 16 raised to its position index (16^0 = 1 on the right, 16^1 = 16, 16^2 = 256, etc.), and sum the products.
    • Example: Convert 3C_16 to decimal:
      • (3 × 16^1) + (12 × 16^0) = 48 + 12 = 60_10.

Worked example

A microcontroller status register contains the 8-bit pattern 01011110_2. Express this unsigned integer in decimal and hexadecimal, and verify that both answers agree.

  1. Binary to decimal: Using place values 128, 64, 32, 16, 8, 4, 2, 1:
    • 1 appears under 64, 16, 8, 4, and 2.
    • Sum: 64 + 16 + 8 + 4 + 2 = 94_10.
  2. Binary to hexadecimal: Split 01011110_2 into two 4-bit nibbles:
    • Left nibble 0101_2 = 4 + 1 = 5_10 = 5_16.
    • Right nibble 1110_2 = 8 + 4 + 2 = 14_10 = E_16.
    • Combine: 5E_16.
  3. Cross-check hexadecimal back to decimal:
    • (5 × 16^1) + (14 × 16^0) = 80 + 14 = 94_10. Both results match.

Check your understanding

  1. Why do electronic computers represent data in binary rather than decimal?
  2. Convert the unsigned binary integer 10011010_2 into both decimal and hexadecimal.
  3. Convert 197_10 into an 8-bit binary integer and then into hexadecimal.
  4. Explain why a hexadecimal digit always maps cleanly to 4 binary bits, and give one situation where programmers use hexadecimal instead of binary.

Common mix-up

It is easy to think: An 8-bit binary integer with all 1s (11111111_2) equals 256, or that the first remainder when dividing by 2 or 16 goes on the far left.

Instead, remember: An 8-bit byte holds 256 possible values because 0 (00000000_2) is the first value, so the largest value is 255 (11111111_2). In repeated division, the first remainder is the least significant digit (far right), and the final remainder is the most significant digit (far left).

Quick recap

  • Computers use binary (0/1) because transistor switches are reliable and noise-resistant in two states.
  • An 8-bit byte stores 256 unsigned integers (0–255); b denotes bits, B denotes bytes, SI prefixes scale by 1,000, and IEC prefixes scale by 1,024.
  • Binary-to-decimal and decimal-to-binary conversions use positional powers of 2 (or doubling and repeated division by 2).
  • Hexadecimal (base-16, 0–9 and A–F) provides a compact representation where each digit maps directly to one 4-bit nibble.
  • Decimal-to-hexadecimal and hexadecimal-to-decimal conversions use repeated division by 16 and positional powers of 16 (16^0, 16^1, ...).

Textbook reading

  • Computer Science (Baumgarten, Ganea, Turland, 2025), A1 Computer fundamentals > A1.2 Data representation and computer logic > A1.2.1 Principal methods of representing data, Book pp. 24–31 (PDF pp. 34–41).
  • Read these pages to reinforce the lesson; this original explanation does not replace the textbook.

Sources and further learning

  • IB Computer Science Guide (first assessment 2027), A1.2.1: Describe the principal methods of representing data (Guide p. 29; PDF p. 35).
  • Computer Science (Baumgarten, Ganea, Turland, 2025), A1.2.1 Principal methods of representing data, Book pp. 24–31 (PDF pp. 34–41). All worked examples and conversion tables above are original.
Check your understanding5 questions · 10 marks · 12 min
Take the lesson check
Something not right?