Home > Web Front-end > JS Tutorial > How to convert binary to decimal in javascript

How to convert binary to decimal in javascript

青灯夜游
Release: 2022-02-17 18:58:20
Original
6657 people have browsed it

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

How to convert binary to decimal in javascript

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])
Copy after login

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));//转成十进制
Copy after login

How to convert binary to decimal in javascript

[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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template