From Maxim’s World of Stuff

HowToProgram: Numbers

"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.

Binary

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:

%10000110

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:

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.

Hexadecimal

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 $ sign:

$a10c

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:

Retrieved from http://www.smspower.org/maxim/HowToProgram/Numbers
Page last modified on November 02, 2010, at 03:32 PM