Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the conversion of 36-ary in javascript

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Most people do not understand the knowledge points of this article "javascript how to achieve 36-base conversion", so the editor summarizes the following contents, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "javascript how to achieve 36-base conversion" article.

Javascript to achieve 36-ary conversion methods: 1, through the "Number.parseInt (string, radix)" conversion; 2, through the "Number.toString (radix)" method conversion.

This article operating environment: Windows7 system, javascript1.8.5 version, DELL G3 computer

How does javascript realize the conversion of base 36?

Js arbitrary binary conversion (binary, octal, decimal. 36 system)

Binary conversion can only occur on numbers, that is, Number types, so to perform binary conversion, that is, you need to use the method on the Number type, and there are two ways:

ParseInt (string, radix) or parseInt (string, radix), the former is the global method, is the previous specification, and now the specification has been changed to the method under Number.

Number.toString (radix)

However, since most languages only support octal, decimal and hexadecimal literal values, js can only convert between string and number types, that is, it can only convert other string to decimal number, or decimal number to other string.

Var a = 0xa racket 0x represents hexadecimal, but js is forced to be converted to decimal, 0xa = = 10var b = 010; 8a*b / / = 80 1, Number.parseInt (string, radix)

This is a string (which can only be made up of letters and numbers). This can only be converted from low to high, such as binary to octal, but octal cannot be converted to binary. Radix represents binary, with a value of 2x 36.

Number.parseInt ('010) / / 8Number.parseInt (' 20) / NaNII, Number.toString (radix)

This function can only convert a decimal number to an arbitrary string. Again, radix represents a binary with a value of 2x 36.

(10) .toString (2) / / "1010" to binary (10) .toString (16) / / "a" to hexadecimal (1000). ToString (36) / / "rs" to 36 is the content of this article on "how to convert javascript to 36". I believe everyone has a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge. Please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report