off by one in Ox.encodeBase26

This commit is contained in:
rolux 2012-05-27 22:59:43 +02:00
parent f030596468
commit b6411d485a

View file

@ -4,14 +4,22 @@
Ox.encodeBase26 <b> Encode a number as bijective base26
See <a href="http://en.wikipedia.org/wiki/Bijective_numeration">
Bijective numeration</a>.
> Ox.encodeBase26(0)
''
> Ox.encodeBase26(1)
'A'
> Ox.encodeBase26(26)
'Z'
> Ox.encodeBase26(27)
'AA'
> Ox.encodeBase26(4461)
'FOO'
@*/
Ox.encodeBase26 = function(number) {
var string = '';
while (number) {
string = String.fromCharCode(64 + number % 26) + string;
number = parseInt(number / 26);
string = String.fromCharCode(65 + (number - 1) % 26) + string;
number = Math.floor((number - 1) / 26);
}
return string;
};