Logic behind base to number conversion

number-systems

I am trying to understand and visualize the logic behind the base conversion method.

By "base" I mean how many numbers in a number system:

  1. The decimal number system we use every day has 10 digits
    {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} and so it is Base 10
  2. A binary digit can only be 0 or 1, so is Base 2
  3. A hexadecimal digit can be {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C,
    D, E, F}, so is Base 16
  4. And we can use letters {A, B, C, …, X, Y, Z}, and we get Base 26

Like in base 26 for AAA its 1* 26*26 + 1*26 + 1

Why formula is:- digit * ( base )^position index

Best Answer

Because it works.

We need a way to express every possible whole numbers.

By having a base $b$ (assuming $b$ is a whole number larger than one) we can simply use the $b$ different digits to list the first $b$ whole numbers from $0$ to $(b-1)$.

(You might ask why $0$ to $b-1$ rather than $1$ to $b$. Technically it is arbitrary. But the indexing works out better if we start at "nothing")

That's the first group of $b$ numbers. We can do a second batch of $b$ numbers by putting a $1$ in front and relisting the $b$ digits after the $1$ for $1\color{blue}0$ to $1\color{blue}{(b-1)}$. This next group of number will go from $1\color{blue}0= b$ to $1\color{blue}{(b-1)} = b + (b-1) =2*b - 1$.

So those are the first $2b$ numbers from $0$ to $2b -1$.

We can do a third, fourth and fifth group of $b$ numbers (assuming our $b$ is that large by placing a $2,3,4$ befor and repeating the $b$ digits. We can do this for $b$ groups of $b$ from:

$\underbrace{\underbrace{0, 1,2 ,...,(b-1)}_{b} + \underbrace{10, 11,12 ,...,1(b-1)}_{b}+ \underbrace{20, 21,22 ,...,2(b-1)}_{b}+...... \underbrace{(b-1)0, (b-1)1,(b-1)2 ,...,(b-1)(b-1)}_{b}}_{b\text{ groups of }b\text{ numbers each}}$

This $b$ groups of $b$ numbers so this is $b^2$ numbers from $0$ to $b^2 -1$. The the number $ka$ would the int $k+1$th group which has the numbers from $k*b$ to $k*b + (b-1)$ and this is the $a+1$ number in the group and is the number $k*b + a$. (Okay, I admit it. The indexing from $0$ is confusing sometimes... but trust me... on the whole it is easier.

Now we have run out of two digit combos after $b^2$ numbers. (Which makes sense. We can have $b$ options for the first digit and $b$ for the second of $b^2$ total.)

But we can do another set of $b^2$ numbers but putting a $1$ before the two digits.

And if we put the $b$ digits before the two digits we can get $b$ groups of $b^2$ number making a total of $b^3$ numbers ranging from $0$ to $b^3-1$ but having $0...(b-1)$ being the numbers $0$ to $b-1$. $10$ to $(b-1)(b-1)$ being so that the number $an = a*b + n$ being the numbers from $b$ to $(b-1)*b + (b-1) = b^2-1$. And then numbers $100$ to $(b-1)(b-1)(b-1)$ where $amn$ would be the $a+1$th group of $b^2$ numbers which go from $ab^2$ to $a*b^2 + (b^2-1)$ and within that group it is the $m+1$th group of $b$ numbers that go from $a*b^2 + m*b$ to $a*b^2 + m*b + (b-1)$ and it is the $n+th$ number in the group so is $n$ more than $a*b^2 + m*b$ or is $a*b^2 + m*b + n$.

And we bootstrap up. We can get $(b-1)$ more groups of $b^3$ numbers but putting $1$ to $(b-1)$ before them to represent the first $b^4$ numbers with $4$ digits and so on.

It works.

And that's really all there is that can be said.

We do it because it will work.