
Everything in this appendix is used somewhere in the course; it is here so you can look it up in one place.
A bit is 0 or 1. A byte is eight bits, so it can hold 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 = 256 different values: 0 to 255.
Each bit of a byte is worth a power of two, from the right:
| Bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|---|---|---|---|
| Worth | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
| In hex | 80 | 40 | 20 | 10 | 08 | 04 | 02 | 01 |
E5 is 1110 0101 in binary: 128 + 64 + 32 + 4 + 1 = 229.
Hex counts in sixteens, with digits 0-9 then A-F:
| Hex | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Decimal | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
A two-digit hex number is first digit x 16 + second digit: E5 = 14 x 16 + 5 = 229. Every byte is exactly two hex digits, 00 to FF; one hex digit is four bits, so each digit of a byte stands for half of it.
Values that turn up again and again in this course:
| Hex | Decimal | Where |
|---|---|---|
0A | 10 | Line feed - the end of a line (S6, S16) |
0D | 13 | Carriage return - before the line feed on the Einstein (S22) |
15 | 21 | A track's size in the size table: 21 x 256 = 5,376 (S8) |
1A | 26 | The end of a text file (S16) |
20 | 32 | A space - pads names (S13) |
28 | 40 | The number of tracks (S8) |
2A | 42 | Gap 3 on Einstein discs (S9) |
7F | 127 | Every bit but the top one (S13) |
80 | 128 | The top bit - the lock (S13); a full extent's record count |
E5 | 229 | Blank disc; a free or deleted directory slot (S12) |
100 | 256 | A header's size; where a track's sector data starts (S9) |
200 | 512 | A sector (S10) |
A number over 255 needs two bytes. The Einstein's discs and their images store them low byte first - little-endian: 512 is 0x0200, stored as 00 02. The value is first byte + 256 x second byte.
int.from_bytes(b"\x00\x02", "little") # 512 (S8)
(512).to_bytes(2, "little") # b'\x00\x02' (S19)
| You write | It means |
|---|---|
0xE5 | The number 229, typed in hex (S4) |
hex(229) | The text '0xe5' (S4) |
f"{229:02X}" | The text 'E5': hex, capitals, at least 2 digits (S6) |
x // y, x % y | Whole times, and remainder (S4) |
b & 0x80 | 128 if the top bit of b is set, else 0 (S13) |
b & 0x7F | b with the top bit cleared (S13) |
b"...", bytes([...]) | Bytes (S5) |
This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.