Javascript Number to_hex()

Description

Javascript Number to_hex()


Number.prototype.to_hex = function() {
 if (this === 0) {
  return "00";
 }

 var chars = "0123456789ABCDEF";
 var n = Math.max(0, this);
 n = Math.min(n, 255);/*  w w w.j  av  a2 s. c o m*/
 n = Math.round(n);
 return chars.charAt((n - n % 16)/16) + chars.charAt(n % 16);
};



PreviousNext

Related