Principal methods of representing data
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
| Term | Simple 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). |
| Bit | A single binary digit (0 or 1). |
| Nibble | A group of 4 bits (0000_2 to 1111_2), which corresponds directly to one hexadecimal digit. |
| Byte | A 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). |
| Noise | Unwanted 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):
- 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. - Alignment with digital logic: Boolean algebra operates on two truth values (
0/false and1/true), allowing arithmetic and control circuits to be built directly from simple logic gates. - 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^0through2^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:
-
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 a1underneath it.- Example: Convert
11010101_2to decimal:
128643216842111010101128 + 64 + 16 + 4 + 1 = 213_10 - Example: Convert
-
Doubling method: Start with
0(or the leftmost1) at the MSB, move left to right, and at each bit compute(current total × 2) + bit:- Using
11010101_2, the step-by-step totals are0×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, and106×2+1 = 213_10.
- Using
Decimal to binary
- Repeated division by 2: Divide the decimal number by
2repeatedly, recording each quotient and remainder (0or1) until the quotient reaches0. 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_10to binary:75 ÷ 2 = 37remainder1(LSB)37 ÷ 2 = 18remainder118 ÷ 2 = 9remainder09 ÷ 2 = 4remainder14 ÷ 2 = 2remainder02 ÷ 2 = 1remainder01 ÷ 2 = 0remainder1(MSB)- Reading from last remainder to first gives
1001011_2, padded to 8 bits as01001011_2.
- Example: Convert
- 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, write1and subtract it; otherwise write0.- For
75_10:128 > 75(0),64 ≤ 75(1, remaining11),32 > 11(0),16 > 11(0),8 ≤ 11(1, remaining3),4 > 3(0),2 ≤ 3(1, remaining1),1 ≤ 1(1, remaining0), giving01001011_2.
- For
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.
| Decimal | Hex | 4-bit binary | Decimal | Hex | 4-bit binary |
|---|---|---|---|---|---|
0 | 0 | 0000 | 8 | 8 | 1000 |
1 | 1 | 0001 | 9 | 9 | 1001 |
2 | 2 | 0010 | 10 | A | 1010 |
3 | 3 | 0011 | 11 | B | 1011 |
4 | 4 | 0100 | 12 | C | 1100 |
5 | 5 | 0101 | 13 | D | 1101 |
6 | 6 | 0110 | 14 | E | 1110 |
7 | 7 | 0111 | 15 | F | 1111 |
Converting between binary and hexadecimal
- 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_2to hexadecimal:- Split into nibbles:
1011and0111 - Convert each nibble:
1011_2 = 8+2+1 = 11_10 = B_16;0111_2 = 4+2+1 = 7_10 = 7_16 - Result:
B7_16.
- Split into nibbles:
- Example: Convert
- 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_16to binary:D_16 = 13_10 = 1101_2and4_16 = 4_10 = 0100_2- Result:
11010100_2.
- Example: Convert
Converting between decimal and hexadecimal
- Decimal to hexadecimal: Divide repeatedly by
16until the quotient is0. Record each remainder (0–15), convert remainders10–15toA–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_10to hexadecimal:219 ÷ 16 = 13remainder11(11 = B)13 ÷ 16 = 0remainder13(13 = D)- Reading last remainder to first gives
DB_16.
- Example: Convert
- Hexadecimal to decimal: Convert each hex digit to its decimal value (
0–15), multiply by16raised to its position index (16^0 = 1on the right,16^1 = 16,16^2 = 256, etc.), and sum the products.- Example: Convert
3C_16to decimal:(3 × 16^1) + (12 × 16^0) = 48 + 12 = 60_10.
- Example: Convert
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.
- Binary to decimal: Using place values
128, 64, 32, 16, 8, 4, 2, 1:1appears under64,16,8,4, and2.- Sum:
64 + 16 + 8 + 4 + 2 = 94_10.
- Binary to hexadecimal: Split
01011110_2into 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.
- Left nibble
- Cross-check hexadecimal back to decimal:
(5 × 16^1) + (14 × 16^0) = 80 + 14 = 94_10. Both results match.
Check your understanding
- Why do electronic computers represent data in binary rather than decimal?
- Convert the unsigned binary integer
10011010_2into both decimal and hexadecimal. - Convert
197_10into an 8-bit binary integer and then into hexadecimal. - 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
256unsigned integers (0–255);bdenotes bits,Bdenotes bytes, SI prefixes scale by1,000, and IEC prefixes scale by1,024. - Binary-to-decimal and decimal-to-binary conversions use positional powers of
2(or doubling and repeated division by2). - Hexadecimal (base-16,
0–9andA–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
16and positional powers of16(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.