JavaScript/进制:修订间差异
来自康健生活
| 第25行: | 第25行: | ||
var num = 0; | var num = 0; | ||
'4e00'.replace(/(.)(?=[^$])/g, "$1,").split(",").forEach(function(d, i){ | '4e00'.replace(/(.)(?=[^$])/g, "$1,").split(",").forEach(function(d, i){ | ||
d.charCodeAt(1).toString(); // 转为二进制 | //d.charCodeAt(1).toString(); // 转为二进制 | ||
const parseIntD = parseInt(d); | const parseIntD = parseInt(d, 16); | ||
num += parseIntD*Math.pow(16,i); | num += parseIntD*Math.pow(16,('4e00'.length - i - 1)); | ||
})</syntaxhighlight> | })</syntaxhighlight> | ||
2020年6月22日 (一) 11:59的版本
引言
十进制转十六进制
模板:Leftrightflex 也可以简化写法为 模板:Leftrightflex
十六进制转十进制
65535 除 16,余数 15(F),商4095 4095 除 16,余数 15(F),商255 255 除 16,余数 15(F),商15 15 除16,余数 15(F),商0,结束 得16进制为 FFFF 15*Math.pow(16,3)+15*Math.pow(16,2)+15*Math.pow(16,1)+15*Math.pow(16,0);
// 错误示例,没有改完
var num = 0;
'4e00'.replace(/(.)(?=[^$])/g, "$1,").split(",").forEach(function(d, i){
//d.charCodeAt(1).toString(); // 转为二进制
const parseIntD = parseInt(d, 16);
num += parseIntD*Math.pow(16,('4e00'.length - i - 1));
})
No categories