Home >Web Front-end >JS Tutorial >JavaScript simple hexadecimal conversion implementation method

JavaScript simple hexadecimal conversion implementation method

高洛峰
高洛峰Original
2016-12-05 13:32:581855browse

The example in this article describes the implementation method of simple hexadecimal conversion in JavaScript. Share it with everyone for your reference, the details are as follows:

Base conversion under JavaScript is very convenient. The system has provided built-in methods to provide conversion between 2 and 36 bases. The representations directly provided include octal, decimal, and hexadecimal.

var w=function(s){document.write(&#39;<br>&#39;+s)};
//十进制转其他
var x=110;
w(x);
w(x.toString(8));
w(x.toString(32));
w(x.toString(16));
//其他转十进制
var x=&#39;110&#39;;
w(parseInt(x,2));
w(parseInt(x,8));
w(parseInt(x,16));
//其他转其他
//先用parseInt转成十进制再用toString转到目标进制


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