Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Decimal number to others
- */
- let number = 31;
- number.toString(2); // "11111", To Binary string
- number.toString(8); // "37" , To Octal string
- number.toString(16); // "1F" , To Hexadecimal string
- /*
- * Others to Decimal
- *
- * After ECMAScript-2015, Number.parseInt === window.parseInt
- */
- Number.parseInt("11111", 2); // 31, Binary to Decimal
- Number.parseInt("37", 8); // 31, Octal to Decimal
- Number.parseInt("1f", 16); // 31, Hexadecimal to Decimal
- /*
- * Get code of a Chinese character
- */
- let c = "知"; // 30694 (Dec)
- let code = c.charCodeAt().toString(8); // 73745, 073745 === 30694 === 0x77e5
- String.fromCharCode(Number.parseInt(73745, 8)); // "知"
- Number.parseInt("FF", 16).toString(2); // "11111111"
- /////////////
Add Comment
Please, Sign In to add comment