more compact versions of decodeBase128 and decodeBase256
This commit is contained in:
parent
6374f6de6d
commit
d2d92c1ae9
1 changed files with 7 additions and 11 deletions
|
@ -130,7 +130,7 @@
|
|||
str = Ox.char(num & 127) + str;
|
||||
num >>= 7;
|
||||
}
|
||||
return str || '0';
|
||||
return str;
|
||||
};
|
||||
|
||||
/*@
|
||||
|
@ -139,11 +139,9 @@
|
|||
1685487
|
||||
@*/
|
||||
Ox.decodeBase128 = function(str) {
|
||||
var num = 0, len = str.length;
|
||||
Ox.forEach(str, function(char, i) {
|
||||
num += char.charCodeAt(0) << (len - i - 1) * 7;
|
||||
});
|
||||
return num;
|
||||
return str.split('').reverse().reduce(function(p, v, i) {
|
||||
return p + (v.charCodeAt(0) << i * 7);
|
||||
}, 0);
|
||||
};
|
||||
|
||||
/*@
|
||||
|
@ -166,11 +164,9 @@
|
|||
6713199
|
||||
@*/
|
||||
Ox.decodeBase256 = function(str) {
|
||||
var num = 0, len = str.length;
|
||||
Ox.forEach(str, function(char, i) {
|
||||
num += char.charCodeAt(0) << (len - i - 1) * 8;
|
||||
});
|
||||
return num;
|
||||
return str.split('').reverse().reduce(function(p, v, i) {
|
||||
return p + (v.charCodeAt(0) << i * 8);
|
||||
}, 0);
|
||||
};
|
||||
|
||||
/*@
|
||||
|
|
Loading…
Reference in a new issue