Fixed bug in numToBytes and util -> conv
This commit is contained in:
parent
eb62360a49
commit
a753f069a5
3 changed files with 12 additions and 3 deletions
src
11
src/util.js
11
src/util.js
|
@ -26,9 +26,18 @@ module.exports = {
|
|||
* Create a byte array representing a number with the given length
|
||||
*/
|
||||
numToBytes: function(num,bytes) {
|
||||
if (bytes == 0 || (bytes === undefined && num === 0)) return [];
|
||||
if (bytes === undefined) bytes = 8;
|
||||
if (bytes == 0) return [];
|
||||
else return [num % 256].concat(module.exports.numToBytes(Math.floor(num / 256),bytes-1));
|
||||
},
|
||||
|
||||
/**
|
||||
* Create a byte array representing a number with the given length
|
||||
*/
|
||||
bytesToNum: function(bytes) {
|
||||
if (bytes.length == 0) return 0;
|
||||
else return bytes[0] + 256 * bytesToNum(bytes.slice(1));
|
||||
},
|
||||
/**
|
||||
* Turn an integer into a "var_int".
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue