compsci-number-system.html


* created: 2025-06-15T19:00
* modified: 2025-07-12T15:08

title

Number Systems

description

A number system is a writing system for expressing numbers using a consistent set of symbols and rules for their arrangement. It defines how numbers are represented and how calculations are performed.

Representing raw data

In computer science, number systems are crucial for representing and processing data in digital systems. Different number systems are used depending on the context.

The most relevant of which would be Binary, Hexadecimal and Decimal.

Transforming from one to another

There are two main steps we can use to easily convert from one number system to any other number system.

First convert to the base 10 system (decimal) and then calculate the respective representation.

Example

To illustrate how this is done we can look at the following example: 1010 0010 -> Base 7

We first transform in the decimal system:

1010 0010 = 1 \cdot 2^7 + 0 \cdot 2^6 + 1 \cdot 2^5 + 0 \cdot 2^4 + 0 \cdot 2^3 + 0 \cdot 2^2 + 1 \cdot 2^1 + 0 \cdot 2^0 = 164

And then we just perform euclidean division until we get our result:

\begin{align} 164 \div 7 = 23 \; | \; r: 3 \\ 23 \div 7 = 3 \; | \; r: 2 \\ 3 \div 7 = 0 \; | \; r: 3 \\ \\ 323 \end{align}

To get the result we have to write the rest from top to bottom in order.

IEEE 754

Single Precision: 1 bit sign, 8 bit exponent (-127); 23 bit mantissa.

\begin{align} x & = v \cdot m \cdot b^e \\ \\ v & = \text{sign} \\ m & = \text{mantisse} \\ b & = \text{base} \\ e & = \text{exponent} \\ \end{align}

TODO! This should be a separat note:

GiB vs GB

GibiByte (GiB) are based on base 2 and reflect the capacity more accurately (generally speaking).

\begin{align} 4\ \text{GiB} &= 4 \times 2^{10}\ \text{MiB} \\ &= 4 \times 1{,}024\ \text{MiB} \\ &= 4{,}096\ \text{MiB} \\ \\ &= 4 \times 2^{10} \times 2^{10}\ \text{KiB} \\ &= 4 \times 1{,}024 \times 1{,}024\ \text{KiB} \\ &= 4{,}194{,}304\ \text{KiB} \\ \\ &= 4 \times 2^{10} \times 2^{10} \times 2^{10}\ \text{Byte} \\ &= 4 \times 1{,}024 \times 1{,}024 \times 1{,}024\ \text{Byte} \\ &= 4{,}294{,}967{,}296\ \text{Byte} \\ \\ &= 4 \times 2^{10} \times 2^{10} \times 2^{10} \times 8\ \text{bit} \\ &= 4 \times 1{,}024 \times 1{,}024 \times 1{,}024 \times 8\ \text{bit} \\ &= 34{,}359{,}738{,}368\ \text{bit} \end{align}

GigaByte (GB) are based on base 10 and are often used for simplicity (easier to reason with).

\begin{align} 4\ \text{GB} &= 4 \times 10^{3}\ \text{MB} \\ &= 4 \times 1{,}000\ \text{MB} \\ &= 4{,}000\ \text{MB} \\[10pt] \\ &= 4 \times 10^{3} \times 10^{3}\ \text{KB} \\ &= 4 \times 1{,}000 \times 1{,}000\ \text{KB} \\ &= 4{,}000{,}000\ \text{KB} \\ \\ &= 4 \times 10^{3} \times 10^{3} \times 10^{3}\ \text{Byte} \\ &= 4 \times 1{,}000 \times 1{,}000 \times 1{,}000\ \text{Byte} \\ &= 4{,}000{,}000{,}000\ \text{Byte} \\ \\ &= 4 \times 10^{3} \times 10^{3} \times 10^{3} \times 8\ \text{bit} \\ &= 4 \times 1{,}000 \times 1{,}000 \times 1{,}000 \times 8\ \text{bit} \\ &= 32{,}000{,}000{,}000\ \text{bit} \end{align}