“Normal” numbers count from 0 to 9, then increment the “tens” digit, and so on. This is the decimal system; also called base 10 because there are ten digits. We use it because we (mostly) have ten fingers on our hands. Computers don’t have fingers, they have bits, so they generally don’t count this way.
On the lowest level, all computer memory is ones and zeroes. This is base 2. You can express a binary number in WLA DX like this:
This is an 8-bit number. The Z80 works in terms of numbers that are eight binary digits long. “Binary digit” can be shortened to “bit”. So the Z80 is an 8-bit CPU.
Let’s figure out what this means, using a Calculator program. Here’s Windows:
You need to be in “Scientific” mode:
There are some “radio buttons” labelled Hex Dec Oct Bin. You can use these to convert between number bases. Click on Bin to go into binary mode, then enter 10000110. Then click on Dec to convert to decimal; the answer is 134. So %10000110 is the same as 134.
Here are a bunch more things to know about binary numbers:
- Binary numbers can only contain the digits 0 and 1.
- In WLA DX, you tell it a number is binary by putting a
%sign in front of it (with no space).
- When we refer to the individual digits (bits), the high bit (or most significant bit, or MSB) is the first digit.
- The low bit (least significant bit, LSB) is the last digit.
- Bits normally come in groups of eight to make a byte. So when you enter a binary number, make sure it has all eight, to avoid confusion.
We rarely deal with binary numbers directly, unless we want to visualise the individual bits. WLA DX lets us enter numbers in binary, decimal or hexadecimal, so we pick the format that suits us best in each case.
Computers like binary but humans don’t - we have to use a calculator to convert it, and it’s hard to enter. Hexadecimal is base 16, and it lets us represent computer data more efficiently. There are sixteen digits, so we use 0 to 9 and then the letters a to f. The case doesn’t matter; I’ll try to use lowercase for consistency.
Two hexadecimal (or hex) numbers are enough to represent one byte. You enter them in WLA DX by preceding the number with a
You can convert this in Windows Calculator by switching to Hex mode, entering a10c and then switching to Dec. You should get 41228.
Here are some more things to know about hex:
- Don’t forget that $9 + 1 = $a
- There are many ways to represent them; you may see them written as
- When we want to signify that a number is a byte, we will make sure it is two digits by adding a leading zero, e.g. $01
- When we want to signify that a number is a word (16 bits), we will make sure it is four digits by adding leading zeroes, e.g. $0002