off by one in Ox.encodeBase26
This commit is contained in:
parent
f030596468
commit
b6411d485a
1 changed files with 10 additions and 2 deletions
|
@ -4,14 +4,22 @@
|
||||||
Ox.encodeBase26 <b> Encode a number as bijective base26
|
Ox.encodeBase26 <b> Encode a number as bijective base26
|
||||||
See <a href="http://en.wikipedia.org/wiki/Bijective_numeration">
|
See <a href="http://en.wikipedia.org/wiki/Bijective_numeration">
|
||||||
Bijective numeration</a>.
|
Bijective numeration</a>.
|
||||||
|
> Ox.encodeBase26(0)
|
||||||
|
''
|
||||||
|
> Ox.encodeBase26(1)
|
||||||
|
'A'
|
||||||
|
> Ox.encodeBase26(26)
|
||||||
|
'Z'
|
||||||
|
> Ox.encodeBase26(27)
|
||||||
|
'AA'
|
||||||
> Ox.encodeBase26(4461)
|
> Ox.encodeBase26(4461)
|
||||||
'FOO'
|
'FOO'
|
||||||
@*/
|
@*/
|
||||||
Ox.encodeBase26 = function(number) {
|
Ox.encodeBase26 = function(number) {
|
||||||
var string = '';
|
var string = '';
|
||||||
while (number) {
|
while (number) {
|
||||||
string = String.fromCharCode(64 + number % 26) + string;
|
string = String.fromCharCode(65 + (number - 1) % 26) + string;
|
||||||
number = parseInt(number / 26);
|
number = Math.floor((number - 1) / 26);
|
||||||
}
|
}
|
||||||
return string;
|
return string;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue