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

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$

• It seems you already have all you need using this base-$26$ formulas. What do you want exactly, find the letters or find the numbers before $26^k$? – zwim Dec 30 '17 at 1:12
• @zwim I am trying to go from 55 -> BC – Arvind Ganesh Dec 30 '17 at 1:24

## 1 Answer

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$

• It's not quite that because his system doesn't have a $0$ digit, but does have a $26$ digit, so the condition should be $0<r\le b$. – Henning Makholm Dec 30 '17 at 1:20
• @HenningMakholm: thanks. I updated the answer. – Ross Millikan Dec 30 '17 at 1:25
• In fact you should better keep the $q,r$ given by Euclidean division. In ASCII code, the letters are consecutive and you are assured that $\operatorname{chr}(\operatorname{ord}('A')+i)$ with $0\le i\le 25$ represents all the letters, thus making math basis compatible with alphabetic system. I'm pretty sure that keeping $1,...,26$ will call for extra unnecessary conversions. – zwim Dec 30 '17 at 1:56
• @zwim: The question specified how the representation works. Changing the representation would not provide an answer to the question. – Henning Makholm Dec 30 '17 at 2:04
• @zwim: A solution is not "better" -- and is in fact not a "solution" at all -- if it is not a solution to the problem that the OP needs to have solved. The fact that you think another problem would be nicer to solve does not change what the question actually asked for. – Henning Makholm Dec 30 '17 at 3:49