Computer Sciencefor Theatre & Technical Direction

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:

ThingWhy 256
One DMX slotOne byte: 0 to 255, which is why a dimmer has 256 levels
One colour channelOne byte per red, green and blue, so 8-bit colour
A character in ASCIIFits in one byte with room to spare
MIDI velocitySeven 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#

PowerValueWhere you meet it
2⁸256One byte, one DMX slot, one colour channel
2⁹512Slots in a DMX universe
2¹⁰1024One kibibyte, 10-bit ADC resolution
2¹⁶65 53616-bit values, TCP and UDP port numbers
2²⁴16 777 21624-bit colour, the "16.7 million colours" claim
2³²4 294 967 29632-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.

DecimalBinaryHex
000000
501015
101010A
151111F
160001 000010
1281000 000080
2551111 1111FF

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#

PrefixDecimalBinaryDifference
kilo / kibi1 0001 0242.4%
mega / mebi10⁶1 048 5764.9%
giga / gibi10⁹1 073 741 8247.4%
tera / tebi10¹²1 099 511 627 77610%

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.

CommandWhat it does
pwdWhere am I
lsWhat is here (dir on Windows cmd)
cd folderGo into a folder. cd .. goes up
cat filePrint a file
python3 script.pyRun a Python script
node script.jsRun a JavaScript file
git statusWhat has changed
Ctrl+CStop 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#

ThingValue
Bits in a byte8
Values in one byte256, so 0 to 255
Values in two bytes65 536
Bits in one hex digit4
FF in decimal255
80 in hex, in decimal128
DMX slots per universe512
Difference between a gigabyte and a gibibyteAbout 7.4 per cent
Bits in a megabyte8 million, which is the factor everybody forgets
Text encoding to useUTF-8, always
Command that stops a runaway programCtrl+C
Frame duration at 25 fps40 ms
50 per cent of a DMX slot128