Inside the Einstein: The Disc, a TatungBytes course: XtalDOS listing the first practice disc image, on a rainbow sunburst
← Back to Modules
module
28

Appendix I: Hex And Binary, For This Course

Everything in this appendix is used somewhere in the course; it is here so you can look it up in one place.

Bits And Bytes

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:

Bit76543210
Worth1286432168421
In hex8040201008040201

E5 is 1110 0101 in binary: 128 + 64 + 32 + 4 + 1 = 229.

Hexadecimal

Hex counts in sixteens, with digits 0-9 then A-F:

Hex0123456789ABCDEF
Decimal0123456789101112131415

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:

HexDecimalWhere
0A10Line feed - the end of a line (S6, S16)
0D13Carriage return - before the line feed on the Einstein (S22)
1521A track's size in the size table: 21 x 256 = 5,376 (S8)
1A26The end of a text file (S16)
2032A space - pads names (S13)
2840The number of tracks (S8)
2A42Gap 3 on Einstein discs (S9)
7F127Every bit but the top one (S13)
80128The top bit - the lock (S13); a full extent's record count
E5229Blank disc; a free or deleted directory slot (S12)
100256A header's size; where a track's sector data starts (S9)
200512A sector (S10)

Two-Byte Numbers

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)

In Python

You writeIt means
0xE5The 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 % yWhole times, and remainder (S4)
b & 0x80128 if the top bit of b is set, else 0 (S13)
b & 0x7Fb with the top bit cleared (S13)
b"...", bytes([...])Bytes (S5)

Get the Newsletter

New guides, disk images and community finds, roughly once a quarter. No spam, we promise, this isn't Tatung's marketing department.
Your subscription could not be saved. Please try again.
Your subscription has been successful.

Newsletter

Subscribe to our newsletter and stay updated.

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.