A primitive data type is a basic data type built into the programming language. They are not composed of other types. The main primitive types in OCR H446 are:
| Type | Example values | Stored as | Typical size |
|---|---|---|---|
| Integer | -3, 0, 42, 10000 | Two's complement binary | 32 or 64 bits |
| Real / Float | 3.14, -0.001, 2.0 | Floating point (IEEE 754) | 32 or 64 bits |
| Boolean | True, False | 0 (False) or 1 (True) | 1 bit (often 1 byte) |
| Character | 'A', '?', '5' | ASCII or Unicode code point | 8 bits (ASCII), 8–32 bits (Unicode) |
| String | "Hello", "123" | Sequence of character code points | Variable (n × char size) |
Note: a string is not truly primitive (it's a sequence of characters) but is often treated as a built-in type. OCR H446 includes it as a data type you must know.
All data in a computer is stored as binary (base 2) — sequences of 0s and 1s. An unsigned integer represents only non-negative values.
Each bit position has a place value that doubles as you move left:
| Bit position | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|---|---|---|---|
| Place value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
Method: repeatedly divide by 2 and record remainders (bottom-up).
Multiply each bit by its place value and sum the results.
Hexadecimal (base 16) is a compact way to represent binary. Each hex digit represents exactly 4 bits (one nibble).
| Denary | Binary | Hex | Denary | Binary | Hex |
|---|---|---|---|---|---|
| 0 | 0000 | 0 | 8 | 1000 | 8 |
| 1 | 0001 | 1 | 9 | 1001 | 9 |
| 2 | 0010 | 2 | 10 | 1010 | A |
| 3 | 0011 | 3 | 11 | 1011 | B |
| 4 | 0100 | 4 | 12 | 1100 | C |
| 5 | 0101 | 5 | 13 | 1101 | D |
| 6 | 0110 | 6 | 14 | 1110 | E |
| 7 | 0111 | 7 | 15 | 1111 | F |
| Unit | Size |
|---|---|
| Bit | 1 binary digit (0 or 1) |
| Nibble | 4 bits |
| Byte | 8 bits |
| Kilobyte (KB) | 1,000 bytes (SI) or 1,024 bytes (KiB) |
| Megabyte (MB) | 1,000,000 bytes (SI) or 1,048,576 bytes (MiB) |
| Gigabyte (GB) | 10⁹ bytes (SI) or 2³⁰ bytes (GiB) |
| Terabyte (TB) | 10¹² bytes (SI) |
With n bits, the number of distinct values that can be represented = 2ⁿ.
Computers use binary because digital circuits have two stable states (high/low voltage = 1/0). Hexadecimal is used as a shorthand because:
8 questions · 20 marks · instantly marked
| Term | Definition |
|---|