Last active
August 29, 2015 14:05
-
-
Save chemdemo/ff2702e4669cbc5f5e2c to your computer and use it in GitHub Desktop.
Hexadecimal conversion in js.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 十进制转其他 | |
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