demo/full/scripts/lib/bytes.js
/**
 * Transform an integer into an hexadecimal string of the given length, padded
 * to the left with `0` if needed.
 * @example
 * ```
 * intToHex(5, 4); // => "0005"
 * intToHex(5, 2); // => "05"
 * intToHex(10, 1); // => "a"
 * intToHex(268, 3); // => "10c"
 * intToHex(4584, 6) // => "0011e8"
 * intToHex(123456, 4); // => "1e240" (we do nothing when going over 4 chars)
 * ```
 * @param {number} num
 * @param {number} size
 * @returns {string}
 */
Transform an integer into an hexadecimal string of the given length, padded
to the left with `0` if needed.
Transform an integer into an hexadecimal string of the given length padded to the left with ` 0 ` if needed .
function intToHex(num, size) {
  const toStr = num.toString(16);
  return toStr.length >= size ?
    toStr :
    new Array(size - toStr.length + 1).join("0") + toStr;
}
function intToHex ( num , size ) { const toStr = num . toString ( 16 ) ; return toStr . length >= size ? toStr : new Array ( size - toStr . length + 1 ) . join ( "0" ) + toStr ; }
Transform an integer into an hexadecimal string of the given length, padded
 to the left with `0` if needed.
Transform an integer into an hexadecimal string of the given length padded to the left with ` 0 ` if needed .