Home > Web Front-end > JS Tutorial > Analysis of common digital system conversion examples in javascript_javascript skills

Analysis of common digital system conversion examples in javascript_javascript skills

WBOY
Release: 2016-05-16 15:04:28
Original
1264 people have browsed it

The example in this article describes the common digital conversion methods in JavaScript. Share it with everyone for your reference, the details are as follows:

The basic idea is to convert other bases into decimal first, and then convert. This process uses the parseInt function, for example, to convert a hexadecimal number (num) into decimal, num = parseInt(num,16). If you want to convert it into binary, it is as follows: num.toString(2).

One of the functions related to hexadecimal is also very special. The escape function can convert a string into a hexadecimal number.

Here is a comprehensive example:

var a = escape(code); //code是个十六进制形式的字符串,a就是一个十六进制数
var b = parseInt(a,16); // 把十六进制数转化成十进制
var c = b.toString(2); //把十进制转化成二进制
var d = (c+'').slice(-2,-1); //其中c+''把数字转化成一个字符串,是个技巧。取这个二进制数字中的倒数第二个数

Copy after login

Friends who are interested in number system conversion and operations can also check out the tools on this site:

Scientific calculator online use_Advanced calculator online calculation

Online Calculator_Standard Calculator

Online scientific calculator flash version

Readers who are interested in more JavaScript-related content can check out the special topics on this site: "Summary of JavaScript switching effects and techniques", "Summary of JavaScript search algorithm techniques", "Summary of JavaScript animation special effects and techniques", "Summary of JavaScript errors and debugging skills", "Summary of JavaScript data structures and algorithm techniques", "JavaScript traversal Summary of Algorithms and Techniques" and "Summary of JavaScript Mathematical Operation Usage"

I hope this article will be helpful to everyone in JavaScript programming.

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