Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I've googled all the combinations I can, but haven't found an answer to this one, nor can I find it in any "related" StackOverflow Q&A's. In this sequence:

aaa = 1
aab = 2
aac = 3
aad = 4
aae = 5
...

what is the easiest way to convert any other string in the sequence (up to max "zzz") to a number, say "aem", or "svg" as random examples? Is there a spreadsheet formula to do this? (I'm a rudimentary user of LibreOffice Calc, FWIW.)

This must be simple for numerate people. :) Unfortunately, I'm somewhat literate, but not at all numerate! Any help with this appreciated!

share|improve this question
1  
This is just base 26 with a as 0 and with 1 added to every number after converting it from base 26 to the target. Each letter is a digit. a=0 through z=25. From right to left, multiply the first digit by 1, the next by 26, the next by 26*26, etc. and add them up. I don't speak spreadsheet (aren't we supposed to be programmers here?) – Wumpus Q. Wumbley 13 mins ago

1 Answer

I'm not sure which language do you use. Because you mentioned spreadsheet I assume that it's something like Excel. In Excel the formula should look like this:

=(CODE(TEXT)-97)*26*26+
 (CODE(RIGHT(LEFT(TEXT,2),1))-97)*26+
 (CODE(RIGHT(LEFT(TEXT,3),1))-97) +
 1

The first line is responsible for the first letter, the second for the second letter and the third for the last letter. In the last line there is +1 because the result would be computed from 0 not 1.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.