How to convert decimal to binary in jquery

WBOY
Release: 2022-05-18 16:39:07
Original
1842 people have browsed it

In jquery, you can use the toString() method to implement decimal to binary conversion. This method is used to convert a digital object into a string and return the conversion result. When the parameter is set to "2", the returned The result is a binary result, and the syntax is "decimal number.toString(2)".

How to convert decimal to binary in jquery

The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.

How jquery converts decimal to binary

The toString() method can convert a Number object into a string and return the result.

Syntax

NumberObject.toString(radix)
Copy after login

Parameter Description

radix Optional. Specifies the base in which the number is represented, making it an integer between 2 and 36. If this parameter is omitted, base 10 is used. Note, however, that the ECMAScript standard allows implementations to return any value if the parameter is a value other than 10.

Return value

The string representation of the number. For example, when radix is ​​2, the NumberObject is converted to a string representing the binary value.

Throws

A TypeError exception is thrown when the object calling this method is not a Number.

Examples are as follows:

// 十进制数
var d = 15;
// 二进制数 
var b = d.toString(2); // '1111'
Copy after login

Recommended related video tutorials: jQuery video tutorial

The above is the detailed content of How to convert decimal to binary in jquery. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!