Number Systems

An introduction to counting

2022-06-15

In this page:

We are all taught to count during our early years; more specifically, we are all taught to count using the decimal system during our early years. Often we use an abacus and learn the ones, tens, hundreds, thousand approach. We say that the number two thousand, three-hundred and sixty four is represented as \(2,364\), two-thousands, three-hundreds, six-tens and four-ones. This is all pretty obvious due to our familiarity with it, but it’s important to establish the method as it is directly applicable to the other numeric systems, as we’ll see.

First, let’s recap some fundamental algebra. Given a varaible \(X\),

\[\begin{aligned} X^0 &= 1 \\ X^1 &= X \\ X^2 &= X \cdot X \\ X^3 &= X \cdot X \cdot X \end{aligned} \]

\(X^N\), where \(N\) is some integer (whole-number), is equal to \(1\) multiplied by \(X\), \(N\) times. (\(X\) and \(N\) are two letters I chose as they are commonly used. They could be any two letters from any alphabet - english, greek, cyrillic…)

Let’s give \(X\) and \(N\) names. We’ll call \(X\) the base or radix, and \(N\) the exponent. Together, \(X^N\) will be referred to as the ‘exponential’.

We can represent the previous example, \(2,364\), as:

\[ 2,364 = (2 \cdot 10^3) + (3 \cdot 10^2) + (6 \cdot 10^1) + (4 \cdot 10^0) \]

This is the mathematical platform from which we’ll now build our understanding of other commonly used representations.

Binary

Binary is often described as “ones and zeros”, “yes and no” or “on and off”. But what does that actually mean? The decimal system, as we saw, works by multiplying a coefficient from \(0\) - \(9\), by some exponential of base-10 (\(1\), \(10\), \(100\), \(1000\), …). The binary system however multiplies a coefficient of \(0\) or \(1\) by some exponential of base-2.

The binary counting system doesn’t use the exponentials, \(10^0\), \(10^1\), \(10^2\), \(10^3\), …, \(10^N\), it uses \(2^0\), \(2^1\), \(2^2\), \(2^3\), …, \(2^M\).

Let’s take a look at a simple number: \(25\). As with the decimal system representation, our largest multipliers (most significant) will be on the left and the smallest (least significant) will be on the right of the resulting string. Let’s calculate the exponentials first to make life easier for ourselves.

\[\begin{aligned} 2^0 &= 1 \\ 2^1 &= 2 \\ 2^2 &= 4 \\ 2^3 &= 8 \\ 2^4 &= 16 \\ 2^5 &= 32 \end{aligned} \]

Now we’ll construct the number \(25\) from coefficients \(0\) or \(1\), multiplied by the corresponding exponential.

\[\begin{aligned} 25 &= (1 \cdot 2^4) + (1 \cdot 2^3) + (0 \cdot 2^2) + (0 \cdot 2^1) + (1 \cdot 2^0) \\ &= (1 \cdot 16) + (1 \cdot 8) + (0 \cdot 4) + (0 \cdot 2) + (1 \cdot 1) \\ &= 16 + 8 + 1 \end{aligned} \]

The number will therefore be represented as \(11001_2\). The subscript 2 shows that the number is base-2. This will help us distinguish the systems as we continue. We do not include the exponentials (\(2^i\)) in the resulting string, they are implied just as with the decimal system.

Let’s take a look at another number: \(44\).

\[\begin{aligned} 44 &= 32 + 8 + 4 \\ 44 &= (1 \cdot 2^5) + (1 \cdot 2^3) + (1 \cdot 2^2) \\ 44 &= (1 \cdot 2^5) + (0 \cdot 2^4) + (1 \cdot 2^3) + (1 \cdot 2^2) + (0 \cdot 2^1) + (0 \cdot 2^0) \end{aligned} \]

This will be represented by the string: \(101100_2\).

We could use leading zeros to pad the string to a certain size, such as in the 8 bit-byte: \(00101100_2\). This is often considerred less convenient as we are adding redundant information.

Let’s write a few more so we can get the hang of this concept, the table headers are the exponentials and the row elements are the corresponding coefficients.

Number \(2^7\) \(2^6\) \(2^5\) \(2^4\) \(2^3\) \(2^2\) \(2^1\) \(2^0\)
\(128\) \(64\) \(32\) \(16\) \(8\) \(4\) \(2\) \(1\)
1 1
2 1 0
3 1 1
5 1 0 1
17 1 0 0 0 1
57 1 1 1 0 0 1
132 1 0 0 0 0 1 0 0
255 1 1 1 1 1 1 1 1

Remember, we don’t neccessarily have to supply the leading zeros, but we must supply the training zeros (in the most to least significant exponential format).

Mathematic formulation

Let’s explore some more systems after writing mathematics to generalise the problem.

\[\sum_{i=0}^{m}X_i \cdot R^i\]

Where:

The value of \(X_i\) is in the range \(0\) to \(R-1\). Binary = \([0,1]\), Decimal = \([0,9]\). ( \(X \in [a,b]\) means \(X\) is a number in the range \(a\) to \(b\) inclusive.)

List of Base-Systems

Decimal and Binary are but two of the many number systems in use. Here is a list the most commonly used systems:

Name Base
Binary 2
Octal 8
Hexadecimal 16
Duo-decimal 12
Sexagesimal 60
Base-64 64

Octal

Octal is the base-8 system, often used in computing. It offers the convenience of writing numbers in shorter strings than binary. Why would we still use binary then? Binary is the fundamental language used by computers for communicating. Octal is a convenient way for humans to express numbers.

The value \(V\) is given by

\[V = \sum_{i=0}^{m}X_i \cdot 8^i\]

where

\[{X_i \in [0 ,7]}\]

As before, the exponentials are:

\[\begin{aligned} 8^0 &= 1 \\ 8^1 &= 8 \\ 8^2 &= 64 \\ 8^3 &= 512 \\ 8^4 &= 4096 \end{aligned} \]

The number \(128\) would be represented in base-8 by \(200_8\), since \(2 \cdot 8^2=128\). This is more convenient for us to write than the binary equivilent \(10000000_2\).

Another example, \(452\), is written as \(704_8\).

\[\begin{aligned} 452 &= 7 \cdot 8^2 + 0 \cdot 8^1 + 4 \cdot 8^0 \\ 452 &= 448 + 0 + 4 \end{aligned} \]

Hexadecimal

The base-16 system has become a very convenient way to store a number. The base-10 system has 10 numbers, \(0\) - \(9\). We’ll introduce the letters \(A\) - \(F\) from the alphabet to represent the decimal numbers \(10\) - \(15\) respectively.

Num Char
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 A
11 B
12 C
13 D
14 E
15 F

\[V = \sum_{i=0}^{m}X_i \cdot 16^i\]

where

\[{X_i \in [0, F]}\]

The number \(227\) would be represented by \(E3_{16}\):

\[\begin{aligned} 227 &= 14 \cdot 16^1 + 3 \cdot 16^0 \\ &= 224 + 3 \end{aligned}\]

The number \(253\) would be represented by \(FD_{16}\):

\[\begin{aligned} 253 &= 15 \cdot 16^1 + 13 \cdot 16^0 \\ &= 240 + 13 \end{aligned}\]

Base-64

If you have made it this far, well done. Base-64 extends the principal we saw with the hexadecimal system to give us access to 64 characters to use to express a value.

Num Char Num Char
0 A 32 g
1 B 33 h
2 C 34 i
3 D 35 j
4 E 36 k
5 F 37 l
6 G 38 m
7 H 39 n
8 I 40 o
9 J 41 p
10 K 42 q
11 L 43 r
12 M 44 s
13 N 45 t
14 O 46 u
15 P 47 v
16 Q 48 w
17 R 49 x
18 S 50 y
19 T 51 z
20 U 52 0
21 V 53 1
22 W 54 2
23 X 55 3
24 Y 56 4
25 Z 57 5
26 a 58 6
27 b 59 7
28 c 60 8
29 d 61 9
30 e 62 \(+\)
31 f 63 \(/\)

\[V = \sum_{i=0}^{m}X_i \cdot 64^i\]

By using the 64 characters set, we can further reduce the length of a string required to represent a value. The number \(2018\) can be represented as \(fi_{64}\), as:

\[\begin{aligned} f_{64} &= 31_{10} \\ i_{64} &= 34_{10} \\ &= 31 \cdot 64^1 + 34 \cdot 16^0 \\ 2018 &= 1984 + 34 \end{aligned}\]

This may not be the most convenient notaton for mental arithmetic, but this numeric base does permit the transmission of information across the internet in smaller payloads. Some websites use this to generate URLs for their content pages to replace lengthy descriptive URLs.

Duo-decimal & Sexagesimal

A few years ago, Base-12 became the subject of academic thought experiments. It has the integer factors 2, 3, 4 and 6, which make it a convenient base for dividing by 2, 3 or 4, all of which are common fractions we use. The thought was that this would make it easier for people going about their daily lives when the need to divide arises. It hasn’t really taken off.

It is also, less obviously linked to the months in the year and the hours in the day. We do not apply it practically though which is strange. We actually use the Base-12 to count the months during the year, representing them in Base-10 indexing from 1. We do the same with the hours in the day. We split the day into two sets of 12 hours, representing them in Base-10. But it’s even more bizarre when you consider that the seconds in the minute, and the minutes in the hour are base-60, represented textually by base-10. So when it comes to telling the time of a given day, we have three base systems involved.

Summary

We have learnt what the number systems mean, how they work explored how to use them to construct non-negative integer numbers. Negative numbers are likely feature in a future article, keep your eyes pealed.

Back to top
This website: Articles: