为什么 UInt8 0x1 转换为字符串 ☺ nodejs
Why does UInt8 0x1 convert to string ☺ nodejs
btest.js
let b = Buffer.alloc(1);
b.writeUInt8(0x1);
console.log(b)
console.log(b.toString("utf8"));
控制台输出为
node btest2
<Buffer 01>
☺
为什么 b.toString() 输出笑脸 (U+263A) 而不是标题开始 (U+1)
经过进一步测试,我相信 DPenner 是正确的,它是控制台的编码 (ConEmu)。
在 cmd.exe 中,字符正确显示为 SOH。
btest.js
let b = Buffer.alloc(1);
b.writeUInt8(0x1);
console.log(b)
console.log(b.toString("utf8"));
控制台输出为
node btest2
<Buffer 01>
☺
为什么 b.toString() 输出笑脸 (U+263A) 而不是标题开始 (U+1)
经过进一步测试,我相信 DPenner 是正确的,它是控制台的编码 (ConEmu)。 在 cmd.exe 中,字符正确显示为 SOH。