Converting Base 10 numbers to an Alphabetical Number System(Similar to the excel column labelling system)

737 Views Asked by At

I am interested in converting a base 10 number into an Alphabetical Number System (like the one used to label columns in excel.) For example,

$ 55 = BC $ in this system because $ 2*26^1 + 3*26^0 = 55 $.

(The 2 and 3 shown above are because B and C are the second and third letter in the alphabet, respectively.)

Is there some sort of formula which can be used to derive the correct numbers correlating to the Alphabet?

EDIT: I am trying to go from 55 -> BC

Other Examples:

$ AAA = 703 = 1*26^2 + 1*26^1 + 1*26^0 $

$ ZZ = 702 = 26*26^1 + 26*26^0 = 27 * 26 $

$ AA = 27 = 1*26^1 + 1*26^0 $

1

There are 1 best solutions below

5
On

To express a number $n$ in base $b$ ($26$ in your example), you do division with remainder. Write $n=qb+r$ with $0 \le r \lt b$. The units digit is $r$. Now do the same with $q$ and the remainder is the next digit. Keep going until you don't get a quotient. This is the standard approach when you allow $0$ digits and not $b$ digits. In your system you do not allow $0$ and do allow $26$, so the condition on $r$ should be $0 \lt r \le 26$