Do this first
Foundations
Bits and bytes, binary and hex, prefixes, what a file actually is, and eight commands in a terminal. Forty minutes, done once, and the rest of the course stops fighting you. All of it is assumed from Class 1 onwards and none of it is taught there.
Forty minutes, done once, and the rest of the course stops fighting you. None of this is difficult and all of it is assumed from Class 1 onwards.
Why this page exists#
Every class assumes you can count in binary, read a hexadecimal number, say roughly how big a gigabyte is, and open a terminal. None of that is taught in the classes, because a class that stops to explain a byte is a class that never reaches what it was for.
If you have already done Computer Systems and Networking, its foundations page covers the same ground from the network's side, and the two agree deliberately. Do whichever you met first, once. Nobody needs to read both.
Bits, bytes and what they hold#
A bit is one binary digit: 0 or 1. Physically it is a voltage above a threshold or below it, which is where Electronics for Theatre picks it up.
A byte is eight bits, which gives 2⁸ = 256 possible values. That number is everywhere in this industry and it is not a coincidence:
| Thing | Why 256 |
|---|---|
| One DMX slot | One byte: 0 to 255, which is why a dimmer has 256 levels |
| One colour channel | One byte per red, green and blue, so 8-bit colour |
| A character in ASCII | Fits in one byte with room to spare |
| MIDI velocity | Seven bits, so 0 to 127, for historical reasons |
Two bytes gives 2¹⁶ = 65 536, which is 16-bit pan and tilt on a moving light, and why fine control takes two DMX slots rather than one.
Powers of two, the ones to know#
| Power | Value | Where you meet it |
|---|---|---|
| 2⁸ | 256 | One byte, one DMX slot, one colour channel |
| 2⁹ | 512 | Slots in a DMX universe |
| 2¹⁰ | 1024 | One kibibyte, 10-bit ADC resolution |
| 2¹⁶ | 65 536 | 16-bit values, TCP and UDP port numbers |
| 2²⁴ | 16 777 216 | 24-bit colour, the "16.7 million colours" claim |
| 2³² | 4 294 967 296 | 32-bit numbers, IPv4 addresses |
Counting in binary and hexadecimal#
Decimal uses ten digits and each place is worth ten times the one to its right. Binary uses two. Hexadecimal uses sixteen, borrowing A to F for the values ten to fifteen.
| Decimal | Binary | Hex |
|---|---|---|
| 0 | 0000 | 0 |
| 5 | 0101 | 5 |
| 10 | 1010 | A |
| 15 | 1111 | F |
| 16 | 0001 0000 | 10 |
| 128 | 1000 0000 | 80 |
| 255 | 1111 1111 | FF |
Hexadecimal exists because one hex digit is exactly four bits. That makes converting a mechanical job rather than arithmetic: split the binary into fours and read each group off the table. 1111 1111 is FF, and FF is 255, which is full on a DMX slot.
You will meet hex in colour codes (#FF8800), MAC addresses, memory addresses, and every low-level protocol. You do not need to be fast at it. You need to recognise it and not be frightened of it.
Doing it in your head, the only method worth having#
To read a binary byte, write the place values above it and add up the ones that are set:
128 64 32 16 8 4 2 1
1 0 1 1 0 0 0 0 = 128 + 32 + 16 = 176
To go the other way, subtract the largest place value that fits, repeatedly.
Prefixes, and the two kinds of kilo#
| Prefix | Decimal | Binary | Difference |
|---|---|---|---|
| kilo / kibi | 1 000 | 1 024 | 2.4% |
| mega / mebi | 10⁶ | 1 048 576 | 4.9% |
| giga / gibi | 10⁹ | 1 073 741 824 | 7.4% |
| tera / tebi | 10¹² | 1 099 511 627 776 | 10% |
Storage manufacturers use the decimal ones, so a "1 TB" drive shows as 931 GiB in your operating system. Nothing is missing and nobody is lying; two different units share a name.
Bits and bytes are different and the abbreviation is the only clue. A lowercase b is bits, an uppercase B is bytes. A 100 Mb/s network link carries at most 12.5 MB/s. Getting this wrong by a factor of eight is the most common arithmetic mistake in this industry, and it is always in the optimistic direction.
What a file actually is#
A file is a sequence of bytes with a name. Nothing else. The extension is a hint to the operating system about which program to open it with, and it is not enforced: renaming a .mp4 to .txt changes nothing about the bytes.
Text files contain bytes that represent characters, under an encoding. UTF-8 is the answer, it handles every language including 繁體中文, and if something arrives as 測試 it is UTF-8 being read as something else. This is not a corruption; the bytes are fine and the reader is wrong.
Binary files contain bytes meaning whatever the format says. Opening one in a text editor shows nonsense and, worse, saving it there can destroy it.
Line endings differ: Unix and macOS use one character, Windows uses two. Most tools cope. When a file looks like one long line, or every line has a stray character at the end, this is why.
The terminal#
Every class in this course needs one. There is nothing to be afraid of and about eight commands to know.
| Command | What it does |
|---|---|
pwd | Where am I |
ls | What is here (dir on Windows cmd) |
cd folder | Go into a folder. cd .. goes up |
cat file | Print a file |
python3 script.py | Run a Python script |
node script.js | Run a JavaScript file |
git status | What has changed |
Ctrl+C | Stop whatever is running. The most important one |
Two things that save the most time:
Tab completes. Type the first few letters of a name and press Tab. It finishes it, which avoids typing errors in paths, which is the largest single source of "it says the file does not exist".
Up arrow repeats. The last command, and the one before. You will run the same thing dozens of times and typing it out each time is a waste.
Paths. A path starting with / is absolute, from the root of the drive. Anything else is relative to where you are, which is what pwd told you. Most "file not found" errors are a relative path run from a different place than you thought.
The arithmetic this course actually uses#
Six calculations appear repeatedly. Each has a calculator on the tools page that shows its working, and the working is what earns the marks.
Frames and time. frames = seconds × fps, and seconds = frames ÷ fps. At 25 fps a frame is 40 ms. This is Class 6, and it is Class 2's floating point warning in practice.
Data rate. bytes per second = bytes per item × items per second. A 600 pixel LED strip at 3 bytes per pixel and 40 fps is 72 000 bytes per second.
Loop budget. time per pass = 1 ÷ passes per second. A loop that must run 1000 times a second has 1 ms per pass, total, for everything.
Percentages of a byte. A DMX level of 50 per cent is 128, not 127.5, and full is 255, not 256. Off-by-one here is a visible fault on stage.
Powers of two. How many bits do I need for n values? 8 bits for 256, 10 for 1024, 16 for 65 536.
Growth. Doubling the data doubles a linear job and quadruples an n² one. Class 3.
Numbers to know before Class 1#
| Thing | Value |
|---|---|
| Bits in a byte | 8 |
| Values in one byte | 256, so 0 to 255 |
| Values in two bytes | 65 536 |
| Bits in one hex digit | 4 |
FF in decimal | 255 |
80 in hex, in decimal | 128 |
| DMX slots per universe | 512 |
| Difference between a gigabyte and a gibibyte | About 7.4 per cent |
| Bits in a megabyte | 8 million, which is the factor everybody forgets |
| Text encoding to use | UTF-8, always |
| Command that stops a runaway program | Ctrl+C |
| Frame duration at 25 fps | 40 ms |
| 50 per cent of a DMX slot | 128 |