From b6411d485a9205ec9aa78a0c8015e608c1c930bb Mon Sep 17 00:00:00 2001 From: rolux Date: Sun, 27 May 2012 22:59:43 +0200 Subject: [PATCH] off by one in Ox.encodeBase26 --- source/Ox/js/Encoding.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/source/Ox/js/Encoding.js b/source/Ox/js/Encoding.js index ba1dcd4f..9c1e6b90 100644 --- a/source/Ox/js/Encoding.js +++ b/source/Ox/js/Encoding.js @@ -4,14 +4,22 @@ Ox.encodeBase26 Encode a number as bijective base26 See Bijective numeration. + > 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; };