Home>Article>Web Front-end> How to convert hexadecimal to binary in javascript
JS method to convert hexadecimal to binary: 1. Use parseInt() method to convert hexadecimal value to decimal value, syntax "parseInt(hexadecimal value, 16)"; 2 , use the toString() method to convert the obtained decimal value into a binary value, the syntax is "decimal value.toString(2)".
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
If you want to convert hexadecimal to binary, you can use an intermediate base - decimal:
First convert hexadecimal to decimal - -Use parseInt() method
and then convert decimal to binary--Use toString() method
var x = "6e";//这是一个十六进制的字符串表示 var y=parseInt(x, 16);//十六进制转为十进制 var z=y.toString(2);//十进制转为2进制 console.log(z);【Related recommendations:
The above is the detailed content of How to convert hexadecimal to binary in javascript. For more information, please follow other related articles on the PHP Chinese website!