In JavaScript, you can use the parseInt() function to convert a binary value to a decimal value. This function can parse a string with a specified base (base) and return a decimal value. Integer; syntax "parseInt("binary string",2)".
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
In javascript, you can use the parseInt() function to convert binary values to decimal values.
Syntax:
parseInt(stringNum,[radix])
The stringNum parameter is a string that needs to be converted to an integer; the radix parameter is a number between 2 and 36, indicating the base number of the stringNum parameter, and the value It can be omitted when it is 10.
The function of parseInt() is to parse the stringNum string parameter with radix as the base into a decimal number. If the stringNum string does not start with a legal character, NaN will be returned; if an illegal character is encountered during the parsing process, parsing will stop immediately and the parsed value will be returned.
Example:
console.log(parseInt("101110100",2));//转成十进制 console.log(parseInt("1101",2));//转成十进制
[Related recommendations: javascript learning tutorial]
The above is the detailed content of How to convert binary to decimal in javascript. For more information, please follow other related articles on the PHP Chinese website!