Returns the integer i in hexadecimal string form with leading zeroes - Node.js Number

Node.js examples for Number:Hex

Description

Returns the integer i in hexadecimal string form with leading zeroes

Demo Code

  
  /** Returns the integer i in hexadecimal string form,
  * with leading zeroes, such that/* ww w . jav  a2  s. com*/
  * the resulting string is at least byteCount*2 characters long.
  * @param {int} i
  * @param {int} byteCount
  */
  toHexString = function(i, byteCount) {
    var string = (new Number(i)).toString(16);
    while(string.length < byteCount*2) {
      string = '0'+string;
    }
    return string;
  }

Related Tutorials