You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
17 lines
271 B
JavaScript
17 lines
271 B
JavaScript
11 years ago
|
module.exports = encode
|
||
|
|
||
|
var MSB = 0x80
|
||
|
, REST = 0x7F
|
||
|
, MSBALL = ~REST
|
||
|
|
||
|
function encode(num, out, offset) {
|
||
|
out = out || []
|
||
|
offset = offset || 0
|
||
|
|
||
|
while(num & MSBALL) {
|
||
|
out[offset++] = (num & 0xFF) | MSB
|
||
|
num >>>= 7
|
||
|
}
|
||
|
out[offset] = num
|
||
|
return out
|
||
|
}
|