Bits, bytes, and computer memory
Computers represent information using patterns of bits. A bit has two possible values, usually written as 0 and 1. A group of eight bits is called a byte.
Bits can represent numbers, text, pictures, and sounds when a program knows how to interpret the pattern. The pattern alone does not explain what it means.
Make number cards
Imagine four cards labelled 8, 4, 2, and 1. Turn a card face up for a bit of 1 and face down for a bit of 0. Add the visible values.
The pattern 1101 gives 8 + 4 + 0 + 1, which is thirteen. This way of writing numbers is called binary. Eight bits give 256 different patterns; those patterns can represent the whole numbers 0 through 255. That does not mean every Pliro number is stored in one byte.
Read a bit pattern
Pliro does not need a special binary literal for this experiment. We use ordinary numbers in a list.
# language: en
let bits = [1, 1, 0, 1]
let value = 0
for bit in bits:
set value = value * 2 + bit
say value
Multiplying by two makes room for the next binary digit. Adding the bit puts that digit in place. After each round, the running values are 1, 3, 6, and 13.
Predict, then run
Which ordinary number does 1101 represent?
13
Your challenge
Try the pattern [1, 0, 1], using the cards 4, 2, and 1. Predict its value first. Only put zeros and ones in the list; other numbers would not describe bits.
Memory and saving
Working memory, often called RAM, is like a desk for things a running program is using. Saved storage is more like a cupboard that can keep a file after the program closes. Saving the source code does not automatically save its current score.
A common mistake
One visible character is not always one byte. Pliro source text uses UTF-8, where different characters can use different numbers of bytes. length counts text code points, not file bytes. You can learn programming without calculating the byte size of every value.
KiB and MiB: counting larger amounts
A KiB (kibibyte) is 1,024 bytes. A MiB (mebibyte) is 1,024 KiB, or 1,048,576 bytes. Pliro’s storage limits use these units. The decimal labels kB and MB mean 1,000 and 1,000,000 bytes. Read the label instead of assuming every “kilo” means the same count.
A 64 KiB limit is a byte limit. With UTF-8, different text can use different byte counts even when it has the same number of code points. Stored JSON also includes its punctuation and field names.
