Javascript Number toHexStr()

Description

Javascript Number toHexStr()



// 65 to "41"//ww  w  .  j a  v a  2 s .c o m
Number.prototype.toHexStr = function() {
 if (this > 0xff) {
  return new Error("the value is out of range")
 }
 var hexStr = this.toString(16).toUpperCase();
 if (hexStr.length == 1) {
  hexStr = "0" + hexStr;
 }
 return hexStr;
};



PreviousNext

Related