/ Published in: JavaScript

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function toHex(number, min) { var hexes = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F']; var hex = ''; var min = min || 2; var nibble; do { nibble = number & 0x0f; number = number >> 4; hex = hexes[nibble] + hex; } while( number ); if( hex.length < min ) { hex = new Array(min-hex.length+1).join('0') + hex; } return '0x'+hex; }
Comments
