Data Types and Number Systems
Why Does Data Need a Type?
Every piece of data stored in a computer has a data type. The type tells the computer how many bytes to reserve, which operations are allowed, and how the binary pattern in memory should be interpreted. A sequence of bits can mean a whole number, a fraction, a letter or a logical true/false value — the data type is what determines the meaning.
The Five Core Data Types
Your exam requires you to know five data types:
- Integer — a whole number, positive or negative, with no decimal point. Examples: 42, −7, 0. Stored in a fixed number of bytes (often 2 or 4).
- Real (also called float) — a number that can have a fractional part. Examples: 3.14, −0.5, 100.0. Stored using a floating-point representation that can handle a vast range of values.
- Character — a single symbol: a letter, digit, space or punctuation mark. Stored as a numeric code (see the lesson on ASCII and Unicode). Example: ‘A’ is stored as the number 65.
- String — a sequence of zero or more characters. Examples: “hello”, “42”, “” (empty string). Strings are stored as consecutive character codes in memory.
- Boolean — a value that can only be
TrueorFalse. Used in conditions and logic. Stored as a single bit (1 for True, 0 for False), though in practice a full byte is often reserved.
The five data types you must know are: integer (whole number), real (decimal number), character (single symbol), string (sequence of characters) and Boolean (True or False). Choosing the wrong type wastes memory or causes errors.
Number Systems: Denary, Binary and Hexadecimal
Computers process everything in binary (base 2), but humans normally count in denary (base 10, using digits 0–9). A third system, hexadecimal (base 16, using 0–9 then A–F), gives programmers a compact way to read and write binary patterns. One hex digit always represents exactly four binary bits (a nibble).
| Denary | Hex | 4-bit Binary |
|---|---|---|
| 0 | 0 | 0000 |
| 5 | 5 | 0101 |
| 10 | A | 1010 |
| 15 | F | 1111 |
| 16 | 10 | 0001 0000 |
Converting Denary to Binary
The easiest method uses a column header table. Write the powers of 2 from right to left, then subtract each column value from the remaining total if possible, placing a 1 in that column, or 0 if not.
Column values (8-bit): 128, 64, 32, 16, 8, 4, 2, 1.
45 < 128 → 0. 45 < 64 → 0. 45 ≥ 32 → 1, remainder 13. 13 < 16 → 0. 13 ≥ 8 → 1, remainder 5. 5 ≥ 4 → 1, remainder 1. 1 < 2 → 0. 1 ≥ 1 → 1.
Result: 00101101. Check: 32 + 8 + 4 + 1 = 45. Correct.
Converting Binary to Denary
Write the binary number under the column headers, then add up the column values where there is a 1. For example, 10110010: columns with 1s are 128, 32, 16, 2 → 128 + 32 + 16 + 2 = 178.
Working with Hexadecimal
Because one hex digit = four binary bits, conversion between hex and binary is fast. To convert binary to hex, split the bits into groups of four (from the right), then replace each group with the matching hex digit. To convert hex to binary, reverse the process — expand each hex digit back into four bits.
Binary to hex: 10111100 → split: 1011 and 1100 → B and C → hex BC.
Hex to denary: BC → B = 11, C = 12. Value = (11 × 16) + (12 × 1) = 176 + 12 = 188.
Denary to hex: 188 ÷ 16 = 11 remainder 12 → B remainder C → hex BC. Always verify your answer.
One hex digit always represents exactly four binary bits. This makes hex a compact shorthand: 8-bit binary needs two hex digits, 16-bit needs four. Programmers use hex for memory addresses, colour codes and error messages because it is far shorter than writing raw binary.
A nibble is four bits. A byte is eight bits (two hex digits). Knowing the nibble boundary is what makes hex-to-binary conversion so quick: you never have to deal with the whole number at once, just one nibble at a time.