### Decimal

Humans tend to count in 10’s; probably because we’ve usually got 10 fingers. As a result, we work in decimal, otherwise known as base 10. You may remember doing a decimal place exercise like this in maths:

Each column can only contain the digits 0 to 9. The column headings are increasing powers of 10 starting at 0 from the right and going to the left. So the first column is 10 to the power of 0, or 1. The second is 10 to the power of 1, or 10, third is 10 to the power of 2, or 100, and so on.

So, there are several ways of representing 1982 in decimal:

- 1982
- 1 x 1000 + 9 x 100 + 8 x 10 + 2= 1982
- 1 x
**10**³ + 9 x**10**² + 8 x**10**¹ + 2 x**10**º = 1982

If you don’t believe me, get a calculator and work it out for yourself. Note the figures in bold; the reason will become apparent in a moment.

### Binary

Computers don’t have 10 fingers. In fact, they only have 2. The fingers are actually voltages in computer circuits; the first finger is represented by no voltage, the second is represented by some voltage. As a result, they work in binary, otherwise known as base 2.

So, given that information, here is a binary place value chart:

Each column can only contain the bit 0 or 1. Each column heading is an increasing power of 2, starting at 0 from the right and going to the left. So the first column is 2 to the power of 0, or 1. The second is 2 to the power of 1 or 2, third is 2 to the power of 2, or 4, and so on.

The assembler I am using for the blog examples prefixes hexadecimal numbers with an percent (“%”) character.

So there are several ways of representing the binary number 01100010:

- %01100010
- 0 x 128 + 1 x 64 + 1 x 32 + 0 x 16 + 0 x 8 + 0 x 4 + 1 x 2 + 0 x 1
- 0 x
**2**^{7}+1 x**2**^{6}+ 1 x**2**^{5}+ 0 x**2**^{4}+ 0 x**2**^{3}+ 0 x**2**^{2}+ 1 x**2**^{1}+0 x**2**^{0}

This also gives us a way to convert binary to decimal; if you do the sum above you will realise that %01100010 is 64 + 32 + 1, or 87. Did you see my shortcut? I just added all column headings together which contained a “1”.

So, you now know what a bit is (a **b**inary dig**it**). This is the smallest amount of information a computer can represent. There are other units of information:

- A nibble is 4 bits and can represent numbers between 0 and 15.
- A byte (B) is 8 bits and can represent numbers between 0 and 255.
- A word is 2 bytes, or 16 bits and can represent numbers between 0 and 65,535
- A kilobyte (KB) is 1024 bytes
- A megabyte (MB) is 1024 kilobytes

“Wait!” I hear you say, “Since when is a kilo of anything 1024?”. Computer people think they are comedians, with names of units like nibble and byte, but they are also quite sensible. 1024 is the nearest number to 1000 that is a power of 2 (1024 = **2**^{10}).

You will find that nearly everything in machine code will revolve around binary!

### Other number systems based upon powers of 2…

Hexadecimal, or hex for short, is base 16. As decimal (Base 10) has 10 unique digits (0-9), hexadecimal has 16. The digits after 9 are represented by the letters A through to F. Each hex digit fits conveniently into a nibble (4 bits) so a byte can be represented by two hex digits.

The assembler I am using for the blog examples prefixes hexadecimal numbers with an ampersand (“&”) character.

So &C9 is %11001001 or 201.

Hex is often used to represent numbers in programming as it is easier to write than a long string of bits and is a lot more readable.

Octal is base 8, so has 8 unique digits (0-7). It’s not used so much these days but was used on computing systems such as the PDP-8 and is used today by Unix systems to set file permissions. It is also used in a couple of native American languages where they count using the gaps between the fingers, not the fingers themselves, but I digress.