Javascript Number toHex()

Description

Javascript Number toHex()


Number.prototype.toHex = function() {
  var hex = this.toString(16);
  if (hex.length == 1) {
    hex = "0" + hex;
  }/*  w w  w . jav a 2  s  .  c  o m*/
  return hex;
}

Javascript Number toHex()

Number.prototype.toHex = function() {
 var upper = ( this.valueOf() >> 4 ) & 0x0F,
  lower = this.valueOf() & 0x0F;
 return upper.toString( 16 ) + lower.toString( 16 );
};



PreviousNext

Related