说明
Number.toString(radix)Converts a number to a string, using a specified radix (base), and returns the string. radix must be between 2 and 36. If omitted, base 10 is used. |
比如中文一字的unicode编码为\u4e00,要想得到对应的unicode十进制编码,在js中不必用4 * 16 * 16 * 16 + 14 * 16 + 0 + 0 = 19968来获得,可以直接用Number.toString()方法得到:
使用
(0x4e00).toString(10) = "19968" |
这样得到的值可以再用js加上前后缀成为"&#" + "19968" + ";" = "一"后可以直接从网页中输出。
反过来,如果知道十进制的一个数字,也可以很容易转换成16进制的值:
(19968).toString(16) = "4e00" |