Skip to content

Two Bytes Together

A byte stops at 255. Put two side by side and you can count to 65535, which is why that number is all over these machines.

A byte counts to 255. That covers plenty: a colour, a letter, a life count, the position of something across a screen.

It does not cover a score. Nobody wants a game where 255 points is the most you can get. It does not cover the number of a place in memory, either, and a machine has thousands of those. So the machine does what you do when you run out of fingers, and it did in Unit 1. It uses more.

Sixteen switches

Put two bytes side by side and you have sixteen switches. The place values carry on doubling past 128, exactly as before: 256, 512, 1024, on up to 32768 for the sixteenth switch.

Turn all sixteen on:

SHOW BIN 1111111111111111
Output
65535

That is 65535, and it is the other number that haunts these machines. If 255 is “the most a byte holds”, 65535 is “the most two bytes hold”. You will meet it as the size of a memory, the top address, and the biggest score many games could keep.

Hex was ready for this

Sixteen switches is unreadable as binary. In hex it is four digits, because each hex digit is four switches, and sixteen is four fours:

SHOW HEX FFFF
Output
65535

Four digits, and you can read the switches straight off them. That is why programmers write addresses in hex. $FFFF tells you every switch is on. 65535 tells you nothing.

The high byte and the low byte

Two bytes side by side are still two bytes, and it helps to keep them apart in your head.

The right-hand byte counts ones, up to 255. It is called the low byte. The left-hand byte counts 256s, and it is the high byte. Each step of the high byte is worth a whole low byte’s range.

In hex the split is visible. A two-byte number is four digits, and the left two are the high byte, the right two the low:

SHOW HEX 1234
SHOW HEX 12 * 256 + HEX 34
Output
4660
4660

Same number both ways. 12 in hex is 18, and 18 × 256 is 4608. 34 in hex is 52. Add them and you have 4660. The high byte is how many 256s; the low byte is what is left.

Watch the moment the low byte fills up:

SHOW HEX 00FF
SHOW HEX 0100
Output
255
256

One more than 255 and the low byte rolls back to 00, while the high byte ticks from 00 to 01. It is the same carry you do on paper when 9 becomes 10, only the column is a whole byte wide.

Why 64K

Sixteen switches give 65536 different patterns, counting the all-zeros one. A machine that numbers its memory with two bytes can therefore tell 65536 places apart, and no more.

You will see that written as 64K. 1024 is close enough to a thousand that people called it a K, and 65536 is 64 × 1024. When someone says a machine has 64K, that is what they mean: every place two bytes can point at.

Which of the two bytes sits first in memory is a decision each machine made for itself. It is one of the first things you learn when you meet one, and it belongs there rather than here.

When it’s wrong, see why

  • A number will not go past 255. You are storing it in one byte. A score, a position on a long level or an address needs two.
  • The value is out by a multiple of 256. The high byte is wrong. Check which byte you put where.
  • 65535 plus one came out as 0. It did. Sixteen switches all on, plus one, is seventeen switches, and the seventeenth has nowhere to go. That is the same wrap-around a single byte does at 255.
  • A four-digit hex number looks like two two-digit ones. It is. Read the left pair as the high byte and the right pair as the low.

What you’ve learnt

  • Two bytes are sixteen switches, and they count to 65535.
  • In hex that is four digits, FFFF, and the split into two bytes shows in the digits.
  • The high byte counts 256s and the low byte counts ones.
  • Sixteen switches can point at 65536 places, which is the 64K these machines advertised.

What’s next

Every number so far has been zero or up. Programs go down too, and the machine has no minus sign. In Unit 4 we see the trick it uses instead.