Format a int i in hex with a left padding of zero of len l - Node.js Number

Node.js examples for Number:Hex

Description

Format a int i in hex with a left padding of zero of len l

Demo Code

/**// www . java  2 s.  c  o  m
 * Format a int i in hex with a left padding of zero
 * of len l
 *
 * Parameters:
 * (int) i - number to format in hex
 * (int) l - length of the left padding
 *
 * Returns:
 * (String) A reprenstation in hex of the number 
 *      with a left padding
 */
function formatHex(i, l) {
  var o = i.toString(16);
  var s = '0';
  while (o.length < l) {
    o = s + o;
  }
  return o;
}

Related Tutorials