#Converting a Word to a Number
20 messages · Page 1 of 1 (latest)
do you know how to rewrite numbers in diff bases
its just simple
A is 1 Z is 26
AA is 27
after aa we have ab then ac .....................
then ba bb bc bd be .......
............
.......
.............
za zb zc ................zz
counting all we have 26*26
then number of zz is 26*26+27
same for all
next series also 26* 26* 26+703
👍
Since you seem interested in this stuff try to recreate this function, btw its 1 y= function
letter2number(A) = 1, letter2number(B) = 2, ..., letter2number(Z) = 26
f(NULL) = 0
f(SEQ:CHAR) = letter2number(CHAR)+26*f(SEQ)
ive got the code if you want it @pale edge
Let word be $a_1a_2a_3...a_n$ \
Let the position of those letters be $p_1$, $p_2$, $p_3$, ..., $p_n$ \
So, the decimal is $(p_1)(26^{n-1}) + (p_2)(26^{n-2}) + (p_3)(26^{n-3}) + ... + (p_{n-1})(26^{1}) + (p_n)(26^0)$ \ \
Viceversa it is a bit harder, but let N be the decimal number. Doing the same as we did but reversed, we know that $\lfloor log{26} N \rfloor = n-1$ where $\lfloor x \rfloor$ is the floor function. \
Now to get $p_1$ you do $\lfloor \frac{N}{n-1} \rfloor$ \
Then, you substract $N - (p_1)(26^{n-1})$ and repeat the process until you get $p_n$