Node.js/Buffer:修订间差异
来自康健生活
| 第101行: | 第101行: | ||
kangkk | kangkk | ||
</pre>}}}} | </pre>}}}} | ||
=== Float32 - Int16 === | |||
{{leftrightflex|<syntaxhighlight lang="javascript"> | |||
const float32 = new Float32Array(1); | |||
// '=' is 0x3d. | |||
float32.set([0x3d],0); | |||
console.log('float32', float32); | |||
const int16 = Int16Array.from( | |||
float32.map(x => (x > 0 ? x * 0x7fff : x * 0x8000)), | |||
); | |||
console.log('int16', int16);</syntaxhighlight>|{{consoleout|<pre> | |||
float32 Float32Array [ 61 ] | |||
int16 Int16Array [ 32707 ] | |||
</pre>}}}} | |||
=== iconv-lite === | |||
{{shc|<syntaxhighlight lang="bash"> | |||
npm i iconv-lite --save</syntaxhighlight>|$|/home/kangkk}} | |||
== 编码 == | == 编码 == | ||