Skip to content

Instantly share code, notes, and snippets.

@chemdemo
Last active August 29, 2015 14:05
Show Gist options
  • Save chemdemo/ff2702e4669cbc5f5e2c to your computer and use it in GitHub Desktop.
Save chemdemo/ff2702e4669cbc5f5e2c to your computer and use it in GitHub Desktop.
Hexadecimal conversion in js.
// 十进制转其他
var x=100;
alert(x);
alert(x.toString(8));
alert(x.toString(32));
alert(x.toString(16));
//其他转十进制
var x='100';
alert(parseInt(x,2));
alert(parseInt(x,8));
alert(parseInt(x,16));
//其他转其他
//先用parseInt转成十进制再用toString转到目标进制
alert(String.fromCharCode(parseInt(150, 16)))
alert(parseInt('300', 16).toString(2));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment