Home  >  Article  >  Web Front-end  >  How to convert decimal to binary in jquery

How to convert decimal to binary in jquery

WBOY
WBOYOriginal
2022-05-18 16:39:071920browse

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)

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'

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!

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