Guest User

Untitled

a guest
May 20th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. /*
  2. * Decimal number to others
  3. */
  4. let number = 31;
  5. number.toString(2); // "11111", To Binary string
  6. number.toString(8); // "37" , To Octal string
  7. number.toString(16); // "1F" , To Hexadecimal string
  8.  
  9. /*
  10. * Others to Decimal
  11. *
  12. * After ECMAScript-2015, Number.parseInt === window.parseInt
  13. */
  14. Number.parseInt("11111", 2); // 31, Binary to Decimal
  15. Number.parseInt("37", 8); // 31, Octal to Decimal
  16. Number.parseInt("1f", 16); // 31, Hexadecimal to Decimal
  17.  
  18. /*
  19. * Get code of a Chinese character
  20. */
  21. let c = "知"; // 30694 (Dec)
  22. let code = c.charCodeAt().toString(8); // 73745, 073745 === 30694 === 0x77e5
  23.  
  24. String.fromCharCode(Number.parseInt(73745, 8)); // "知"
  25. Number.parseInt("FF", 16).toString(2); // "11111111"
  26.  
  27.  
  28. /////////////
Add Comment
Please, Sign In to add comment