Javascript Number toHexString()

Description

Javascript Number toHexString()


Number.prototype.toHexString = function() {
 if (this === null) { return null; }
 if (isNaN(this)) { return this; }
 var num;/*from  w  w w.  ja v  a  2  s  .  co  m*/
 var hex;
 if (this < 0) {
  num = 0xFFFFFFFF + this + 1;
 }
 else {
  num = this;
 }
 hex = num.toString(16).toUpperCase();
 return "0x" + ("00000000".substr(0, 8 - hex.length) + hex);
}

Javascript Number toHexString()

Math.hypot = function(x, y){
 return Math.sqrt(x*x + y*y);
}

Number.prototype.toHexString = function(){
 return ('0' + this.toString(16)).slice(-2);
};



PreviousNext

Related