Home >Web Front-end >JS Tutorial >js hexadecimal conversion example
parseInt("",16) parseInt("",8) parseInt("",2)
a= , a.toString(16) a.toString(8) a.toString(2) a.toString(32)
function decToHex(num) { var newNum = num.toString(16); if(num<16){ return "000"+newNum; } if(num<255){ return "00"+newNum; } if(num<4095){ return "0"+newNum; } if(num<65535){ return newNum; }else { alert("错误"); } }
Related recommendations:
Understand the base conversion and its function in JS
About string and multi-base conversion in PHP Example code of function
Use JavaScript for hexadecimal conversion
The above is the detailed content of js hexadecimal conversion example. For more information, please follow other related articles on the PHP Chinese website!