http://www.atool.org/hexconvert.php
ss = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_@";
function v10toX(n, m) {
m = String(m).replace(/ /gi, "");
if (m == "") {
return ""
}
var a = ss.substr(0, 10);
var b = a + ".";
if (eval("m.replace(/[" + b + "]/gi,'')") != "") {
M("请输入有效的进制数!");
return ""
}
m = m.split(".");
if (m.length > 2) {
M("请输入有效的进制数!");
return ""
}
var a = ss.substr(0, n);
if (m.length == 1) {
m = m[0];
var t = "";
while (m != 0) {
var b = m % n;
t = a.charAt(b) + t;
m = (m - b) / n
}
return t
} else {
var m0 = m[0];
var t = "";
while (m0 != 0) {
var b = m0 % n;
t = a.charAt(b) + t;
m0 = (m0 - b) / n
}
var cnt = 18;
var m1 = m[1];
m1 = parseFloat("0." + m1);
var d = "", b = 0;
while (m1 != 0 && cnt > 0) {
m1 = m1 * n;
b = parseInt(m1);
d = d + a.charAt(b);
m1 = m1 - b;
cnt--
}
return t + "." + d
}
}
function vXto10(n, m) {
m = String(m).replace(/ /gi, "");
if (m == "") {
return ""
}
var a = ss.substr(0, n);
var b = a + ".";
if (eval("m.replace(/[" + b + "]/gi,'')") != "") {
M("请输入有效的" + n + "进制数!");
return ""
}
m = m.split(".");
if (m.length > 2) {
M("请输入有效的" + n + "进制数!");
return ""
}
if (m.length == 1) {
m = m[0];
var t = 0, c = 1;
for (var x = m.length - 1; x > -1; x--) {
t += c * (a.indexOf(m.charAt(x)));
c *= n
}
return t
} else {
var m0 = m[0];
var t = 0, c = 1;
for (var x = m0.length - 1; x > -1; x--) {
t += c * (a.indexOf(m0.charAt(x)));
c *= n
}
var m1 = m[1];
var d = 0, c = 1 / n;
for (var x = 0; x < m1.length; x++) {
d += c * (a.indexOf(m1.charAt(x)));
c /= n
}
return t + d
}
}
function vXtoY(d, b, c) {
a = vXto10(d * 1, b);
if (a == "") {
return ""
}
a = v10toX(c, a);
return a
}
function M(b) {
alert(b)
}
function convert(g, h, i, f) {
var e = document.getElementById(h).value;
var d = document.getElementById(f);
var b = document.getElementById(g).value;
var c = document.getElementById(i).value;
d.value = vXtoY(b, e, c)
}
function convert_c(g, e, f, d) {
var c = document.getElementById(e).value;
var b = document.getElementById(d);
b.value = vXtoY(g, c, f)
};
<div class="row">
<span class="span strong">二 进 制:</span>
<div class="span four xs-four">
<input type="text" id="bin_1" alt="二进制数" title="二进制数" class="input-text" value="10011110101110110100010">
</div>
<span class="span strong">十 进 制:</span>
<div class="span four xs-four">
<input type="text" id="ten_1" alt="十进制数" title="十进制数" class="input-text" value="">
</div>
<button class="button primary small" type="button" onclick="convert_c(2, 'bin_1', 10, 'ten_1');">转换</button>
</div>
<div class="row">
<span class="span strong">十 进 制:</span>
<div class="span four xs-four">
<input type="text" id="ten_2" alt="十进制数" title="十进制数" class="input-text" value="520.1314">
</div>
<span class="span strong">二 进 制:</span>
<div class="span four xs-four">
<input type="text" id="bin_2" alt="二进制数" title="二进制数" class="input-text" value="">
</div>
<button class="button primary small" type="button" onclick="convert_c(10, 'ten_2', 2, 'bin_2');">转换</button>
</div>
<div class="divider form-hr"></div>
<div class="row">
<span class="span strong">十 进 制:</span>
<div class="span four xs-four">
<input type="text" id="ten_3" alt="十进制数" title="十进制数" class="input-text" value="520.1314">
</div>
<span class="span strong">十六进制 :</span>
<div class="span four xs-four">
<input type="text" id="ten_six_3" alt="十六进制数" title="十六进制数" class="input-text" value="">
</div>
<button class="button primary small" type="button" onclick="convert_c(10, 'ten_3', 16, 'ten_six_3');">转换</button>
</div>
<div class="row">
<span class="span strong">十六进制 :</span>
<div class="span four xs-four">
<input type="text" id="ten_six_4" alt="十六进制数" title="十六进制数" class="input-text" value="4f5da2">
</div>
<span class="span strong">十 进 制:</span>
<div class="span four xs-four">
<input type="text" id="ten_4" alt="十进制数" title="十进制数" class="input-text" value="">
</div>
<button class="button primary small" type="button" onclick="convert_c(16, 'ten_six_4', 10, 'ten_4');">转换</button>
</div>
<div class="divider form-hr"></div>
<div class="row">
<span class="span strong">十 进 制:</span>
<div class="span four xs-four">
<input type="text" id="ten_5" alt="十进制数" title="十进制数" class="input-text" value="520.1314">
</div>
<span class="span strong">六十四进制:</span>
<div class="span four xs-four">
<input type="text" id="six_four_5" alt="六十四进制数" title="六十四进制数" class="input-text" value="">
</div>
<button class="button primary small" type="button" onclick="convert_c(10, 'ten_5', 64, 'six_four_5');">转换</button>
</div>
<div class="row">
<span class="span strong">六十四进制:</span>
<div class="span four xs-four">
<input type="text" id="six_four_6" alt="六十四进制数" title="六十四进制数" class="input-text" value="jRSy">
</div>
<span class="span strong">十 进 制:</span>
<div class="span four xs-four">
<input type="text" id="ten_6" alt="十进制数" title="十进制数" class="input-text" value="">
</div>
<button class="button primary small" type="button" onclick="convert_c(64, 'six_four_6', 10, 'ten_6');">转换</button>
</div>