Robust utility function for producing hex number string.
1 2 3 4 5 |
//(c) DBJ.ORG, MIT license applies function hxstr ( v_ , undefined ) { if (isNaN(v_ = Number(v_))) return undefined; return "0x" + (v_.toString(16)).toUpperCase(); } |
This will take anything and return “0x” prefixed hex number in a string, or just undefined, on any mischief attempted.
1 2 3 4 |
hxstr(";"); // '0x0' hxstr({}); // undefined hxstr(23456789); // '0x165EC15' hxstr(1e10); // '0x2540BE400' |
Enjoy …