Computer Science · Topic 02

Number Systems and Data Representation

Computers store and process information using binary digits. Learn how number systems work, how to convert between them, and how digital systems represent different kinds of data.

1. What is a number system?

A number system is a way of representing numbers using a set of symbols. Its base (or radix) tells us how many different digits it uses. In a positional number system, each digit's value depends on its position.

Decimal · Base 10

Digits: 0–9. Commonly used in everyday counting.

Binary · Base 2

Digits: 0 and 1. Fundamental to digital computing.

Octal · Base 8

Digits: 0–7. One octal digit represents three binary bits.

Hexadecimal · Base 16

Digits: 0–9 and A–F, where A=10 through F=15.

2. Positional notation

In base \(b\), a number's value is the sum of each digit multiplied by its corresponding power of \(b\). For whole numbers, the rightmost position has power zero.

Example: Decimal 472

472 = 4 × 10² + 7 × 10¹ + 2 × 10⁰

= 400 + 70 + 2

Example: Binary 1011

1011₂ = 1 × 2³ + 0 × 2² + 1 × 2¹ + 1 × 2⁰

= 8 + 0 + 2 + 1 = 11₁₀

Subscripts indicate the base: 1011₂ is binary, while 1011₁₀ is decimal. Without a subscript, context must make the base clear.

3. Convert between number systems

Decimal to binary

Repeatedly divide the decimal number by 2. Read the remainders from bottom to top.

Convert 13₁₀ to binary.

13 ÷ 2 = 6 remainder 1
 6 ÷ 2 = 3 remainder 0
 3 ÷ 2 = 1 remainder 1
 1 ÷ 2 = 0 remainder 1

Read upward: 1101₂

13₁₀ = 1101₂

Binary to decimal

Multiply each bit by its position's power of 2, then add the results.

Convert 11010₂ to decimal.

11010₂ = 1×16 + 1×8 + 0×4 + 1×2 + 0×1 = 26₁₀

Decimal to hexadecimal

Repeatedly divide by 16 and read the remainders upward. Remainders 10–15 are written A–F.

Convert 254₁₀ to hexadecimal.

254 ÷ 16 = 15 remainder 14
15 ÷ 16 = 0 remainder 15

15 = F, 14 = E
Answer: FE₁₆

Binary to octal or hexadecimal

For octal, group bits in sets of three from the right. For hexadecimal, group bits in sets of four. Add leading zeros on the left if needed.

Binary to octal: 110101₂ → 110 101 → 6 5 → 65₈

Binary to hexadecimal: 11010110₂ → 1101 0110 → D 6 → D6₁₆

4. Basic binary arithmetic

Binary addition follows a few simple rules:

AdditionResult
0 + 00
0 + 11
1 + 01
1 + 110 (write 0, carry 1)
1 + 1 + 111 (write 1, carry 1)

Example: 1011₂ + 0110₂

   1011
 + 0110
 ------
  10001

11 + 6 = 17, so 10001₂ is correct.

5. Bits, bytes, and storage

UnitMeaning
1 byte (B)8 bits
1 kilobyte (KB)1,000 bytes (decimal convention)
1 megabyte (MB)1,000 KB (decimal convention)
1 kibibyte (KiB)1,024 bytes
1 mebibyte (MiB)1,024 KiB

Storage manufacturers commonly use decimal units (KB, MB, GB). Binary units (KiB, MiB, GiB) use powers of 1,024. Some software still uses KB or MB informally for binary quantities, so check the context.

6. How computers represent data

Text

Text is encoded into numbers. ASCII represents a limited set of characters; Unicode provides a much larger system for representing characters from many writing systems. UTF-8 is a widely used Unicode encoding that uses one to four bytes per code point.

Images

Raster images are made of pixels. Each pixel stores colour information using an encoding such as RGB. An uncompressed image's approximate storage depends on its width, height, and bits per pixel.

Uncompressed size in bits ≈ width × height × bits per pixel

This estimate excludes headers, metadata, padding, and compression.

Audio

Digital audio commonly represents sound by sampling its amplitude over time. Sample rate, bit depth, number of channels, and compression affect its quality and file size.

Negative integers

Computers commonly represent signed integers using two's complement. In an \(n\)-bit two's-complement system, the representable range is \(-2^{n-1}\) to \(2^{n-1}-1\).

Example: −5 in 8-bit two's complement

+5        = 00000101
Invert bits = 11111010
Add 1       = 11111011

Therefore −5 = 11111011 (8-bit two's complement)

7. Why binary?

Digital electronic circuits can distinguish two states reliably, such as low and high voltage. These states can represent 0 and 1. Combining bits allows a system to encode numbers, text, instructions, images, sound, and other information.

Binary is not the only possible way to design a computing system, but two-state digital logic is practical and robust for modern computers.

8. Quick knowledge check

Try solving each question before revealing the answer.

Question 1: Convert 1010₂ to decimal.

10₁₀, because 8 + 0 + 2 + 0 = 10.

Question 2: Convert 19₁₀ to binary.

10011₂, because 16 + 2 + 1 = 19.

Question 3: How many bits are in 3 bytes?

24 bits, because 3 × 8 = 24.

Question 4: Convert FF₁₆ to decimal.

255₁₀, because F = 15 and 15 × 16 + 15 = 255.

Key takeaways