Home>Article>Web Front-end> How to convert hexadecimal to binary in javascript

How to convert hexadecimal to binary in javascript

青灯夜游
青灯夜游 Original
2021-12-07 13:50:59 7357browse

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)".

How to convert hexadecimal to binary in javascript

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

##Implementation method:


var x = "6e";//这是一个十六进制的字符串表示 var y=parseInt(x, 16);//十六进制转为十进制 var z=y.toString(2);//十进制转为2进制 console.log(z);

How to convert hexadecimal to binary in javascript

【Related recommendations:

javascript learning tutorial

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn