javascript TypedArray

TypedArray描述了ArrayBuffer

构造

new TypedArray(); // new in ES2017
new TypedArray(length);
new TypedArray(typedArray);
new TypedArray(object);
new TypedArray(buffer [, byteOffset [, length]]);

// where TypedArray is one of:

Int8Array();
Uint8Array();
Uint8ClampedArray();
Int16Array();
Uint16Array();
Int32Array();
Uint32Array();
Float32Array();
Float64Array();
BigInt64Array();
BigUint64Array();
TypeValue RangeSize in bytesDescriptionWeb IDL typeEquivalent C type
Int8Array-128 to 12718-bit two’s complement signed integerbyteint8_t
Uint8Array0 to 25518-bit unsigned integeroctetuint8_t
Uint8ClampedArray0 to 25518-bit unsigned integer (clamped)octetuint8_t
Int16Array-32768 to 32767216-bit two’s complement signed integershortint16_t
Uint16Array0 to 65535216-bit unsigned integerunsigned shortuint16_t
Int32Array-2147483648 to 2147483647432-bit two’s complement signed integerlong int32_t
Uint32Array0 to 4294967295432-bit unsigned integerunsigned longuint32_t
Float32Array1.2×10-38 to 3.4×1038432-bit IEEE floating point number (7 significant digits e.g., 1.1234567)unrestricted floatfloat
Float64Array5.0×10-324 to 1.8×10308864-bit IEEE floating point number (16 significant digits e.g., 1.123…15)unrestricted doubledouble
BigInt64Array-263 to 263-1864-bit two’s complement signed integerbigintint64_t (signed long long)
BigUint64Array0 to 264-1864-bit unsigned integerbigintuint64_t (unsigned long long)

1.int8Array,int16Array都是通过对ArrayBuffer来进行读写的
2.int8Array是将ArrayBuffer中的一个字节当成一个元素,Int16Array则是将ArrayBuffer中的两个字节当成一个元素.
例如:
1)ArrayBuffer中有8个字节,分别为01 02 03 04 05 06 07 08
2)分别根据这个ArrayBuffer创建Uint8,Uint16,和Unit32

var u8 = new Uint8Array(buffer); // length为8  
var u16 = new Uint16Array(buffer); // length为4 
var u32 = new Uint32Array(buffer); // length为2  

3)结果为

[1, 2, 3, 4, 5, 6, 7, 8] //u8
[513, 1027, 1541, 2055] //u16
[67305985, 134678021] //u32

https://www.jb51.net/article/147112.htm
https://developer.51cto.com/art/201704/536718.htm

参考:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray#Syntax

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值