1 function toUtf16(text) {
2 if (text.length === 1) return text.charCodeAt(0).toString(16);
3 const point = text.codePointAt(0);
4 const highBits = 0xd800,
5 lowBits = 0xdc00,
6 bmp = 0x10000;
7 const rest = (point - bmp).toString(2),
8 restHighBits = +("0b" + rest.slice(0, -10)),
9 restLowBits = +("0b" + rest.slice(-10));
10 const _char0Hex = (highBits + restHighBits).toString(16),
11 _char1Hex = (lowBits + restLowBits).toString(16);
12
13 return _char0Hex + _char1Hex;
14 }
15
16 export default toUtf16;
unicode 转 utf16
最新推荐文章于 2023-07-27 11:15:51 发布