When we see a number like 1234 in our normal base10 number system, this actually represents
(1 x 1000) + (2 x 100) + (3 x 10) + (4 x 1)
As we used to say at primary school: Thousands, Hundreds, Tens and Units. Each column is a power of 10.
1000 is 10
3100 is 10
210 is 10
11 is 10
01234=(1x10
3) + (2x10
2) + (3x10
1) + (4x10
0)
The same principle is used in Binary (base 2) but we use powers of two rather than 10.
128 is 2
764 is 2
632 is 2
516 is 2
48 is 2
34 is 2
22 is 2
11 is 2
0A number like 154 (decimal) is encoded as follows in binary:
154(decimal)=10011010(binary)=(1x2
7)+(0x2
6)+(0x2
5)+(1x2
4)+(1x2
3)+(0x2
2)+(1x2
1)+(0x2
0)
154(decimal)=10011010(binary)=(1x128)+(0x64)+(0x32)+(1x16)+(1x8)+(0x4)+(1x2)+(0x1)
Here is how you count in binary:
| Decimal | Binary |
| 0 | 0000 |
| 1 | 0001 |
| 2 | 0010 |
| 3 | 0011 |
| 4 | 0100 |
| 5 | 0101 |
| 6 | 0110 |
| 7 | 0111 |
| 8 | 1000 |
| 9 | 1001 |
| 10 | 1010 |
| 11 | 1011 |
| 12 | 1100 |
| 13 | 1101 |
| 14 | 1110 |
| 15 | 1111 |
At the lowest level, everything in a computer is encoded in binary. The cells in the memory chips are either "on" or "off" - representing "1" or "0". For convenience, the memory cells are grouped into blocks of 8 called bytes and each byte has an address to identifiy it.
Computers love binary, but typing in all thoses 1's and 0's can be a little tedious for programmers, especially for larger numbers. So programmers like to use Hexadecimal (base 16). 16 is a power of 2 and therefore it is much easier to convert between binary and hex than it is to use decimal.
In hex, we have six extra digits between 9 and 10. You count from 0 to 9, then continue A to F, then 10 to 19, 1A to 1F then 20 etc. When you get to 9F, the next number is A0 and so on. When you get to FF, the next number is 100.
Converting between hex and binary is very easy because each hex digit represents exactly 4 bits of binary.
| Hex | Binary |
| 0 | 0000 |
| 1 | 0001 |
| 2 | 0010 |
| 3 | 0011 |
| 4 | 0100 |
| 5 | 0101 |
| 6 | 0110 |
| 7 | 0111 |
| 8 | 1000 |
| 9 | 1001 |
| A | 1010 |
| B | 1011 |
| C | 1100 |
| D | 1101 |
| E | 1110 |
| F | 1111 |
For example, the value A531 in hex is 1010 0101 0011 0001 in binary.
Or, the other way around 0110 1001 1111 0010 in binary is 69F2 in hex.