(Partially adapted from BBC Bitesize, some parts written by me.)
A number base is the number of digits or combination of digits that a system of counting uses to represent numbers.
We, as humans, usually use base 10
, aka the decimal system. This means we count with 10 numbers - 0,1,2,3,4,5,6,7,8,9
For example, the value of the number 124 in decimal place values is actually:
Place value | 10,000 | 1,000 | 100 | 10 | 1 |
---|---|---|---|---|---|
Value | 0 | 0 | 1 | 2 | 4 |
This gives (1 × 100) + (2 × 10) + (1 × 4) = **124
**
Computers use binary (base 2
, with the digits 0,1
) to represent all data and instructions. Bit patterns can represent different types of data including text, image, sound, and integers.
Example - binary number 1111100
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
---|---|---|---|---|---|---|---|
0 | 1 | 1 | 1 | 1 | 1 | 0 | 0 |
Result - (0 × 128) + (1 × 64) + (1 × 32) + (1 × 16) + (1 × 8) + (1 × 4) + (0 × 2) + (0 × 1) = **124**
We also use Hexadecimal in computer science because it is more compact and easier to read than binary, and is an intermediary between binary and decimal/denary numbers.
Hexadecimal uses the digits 0 to 9 and A to F
Decimal | Binary | Hexadecimal |
---|---|---|
0 | 0000 |
0 |
1 | 0001 |
1 |
2 | 0010 |
2 |
3 | 0011 |
3 |
4 | 0100 |
4 |
5 | 0101 |
5 |
6 | 0110 |
6 |
7 | 0111 |
7 |
8 | 1000 |
8 |
9 | 1001 |
9 |
10 | 1010 |
A |
11 | 1011 |
B |
12 | 1100 |
C |
13 | 1101 |
D |
14 | 1110 |
E |
15 | 1111 |
F |
Whereas decimal place values are powers of 10, and binary place values are powers of 2, hex place values are powers of 16.
Example - hex number 7C
65,536 | 4,096 | 256 | 16 | 1 |
---|---|---|---|---|
7 | C |