DataView.prototype.getUint16() - 符号なし16bit整数値で読み込む
DataView.prototype.getUint16()は、参照しているArrayBufferの指定した位置から、符号なし16bit整数値でバイナリデータを読み込むメソッドです。読み込みの範囲が、参照しているArrayBufferのサイズを超えた場合にエラーが発生します。
概要
説明
DataView.prototype.getUint16 ( byteOffset [ , littleEndian ] )
第1引数(byteOffset)には、参照しているバッファから読み込みを開始する位置をByte単位のオフセットで指定する。
第2引数(littleEndian)には、任意でデータの配置方式を指定する。trueならLittle endian、falseならBig endian。省略した場合はtrueになる。
チュートリアル
var arrayBuffer = new Uint8Array( [ 0x00, 0x00, 0x4f, 0xff, 0x8f, 0xff, 0xff, 0xff ] ).buffer ;
var dataView = new DataView( arrayBuffer ) ;
dataView.getUint16( 0 ) ; // 0 (0x0000) [ 0x00, 0x00, 0x4f, 0xff, 0x8f, 0xff, 0xff, 0xff ]
dataView.getUint16( 2 ) ; // 20479 (0x4fff) [ 0x00, 0x00, 0x4f, 0xff, 0x8f, 0xff, 0xff, 0xff ]
dataView.getUint16( 4 ) ; // 36863 (0x8fff) [ 0x00, 0x00, 0x4f, 0xff, 0x8f, 0xff, 0xff, 0xff ]
dataView.getUint16( 6 ) ; // 65535 (0xffff) [ 0x00, 0x00, 0x4f, 0xff, 0x8f, 0xff, 0xff, 0xff ]
デモ
DataView.prototype.getUint16()のデモです。
<!-- このコードは編集できます。 -->
<!DOCTYPE html>
<html>
<head>
<style>
body {
white-space: pre-wrap ;
}
</style>
</head>
<body>
<script>
/** try it! **/
var arrayBuffer = new Uint8Array( [ 0x00, 0x00, 0x4f, 0xff, 0x8f, 0xff, 0xff, 0xff ] ).buffer ;
var dataView = new DataView( arrayBuffer ) ;
var a = dataView.getUint16( 0 ) ;
var b = dataView.getUint16( 2 ) ;
var c = dataView.getUint16( 4 ) ;
var d = dataView.getUint16( 6 ) ;
/** try it! **/
var results = { a:a, b:b, c:c, d:d, } ;
for( var name in results ) {
console.log( name, results[name] ) ;
document.body.appendChild( new Text( name + " = " + results[name] + "\n" ) ) ;
}
</script>
</body>
</html>
サポート状況
Chrome | Firefox | Safari | Edge | IE | Opera | iOS Safari | Android |
---|---|---|---|---|---|---|---|
● | ● 15+ | ● 5.1+ | ● | ● 10+ | ● 11.6+ | ● | ● 4.0+ |
関連記事
- DataView.prototype.getUint8()
- DataView.prototype.getUint8()は、参照しているArrayBufferの指定した位置から、符号なし8bit整数値でバイナリデータを読み込むメソッドです。読み込みの範囲が、参照しているArrayBufferのサイズを超えた場合にエラーが発生します。
- DataView
- DataViewは固定長のバイナリデータを読み書きする機能を備えたオブジェクトです。
- DataView.prototype.setInt16()
- DataView.prototype.setInt16()は、参照しているArrayBufferの指定した位置から、16bit浮動小数点数で上書きするメソッドです。書き込みの範囲が、参照しているArrayBufferのサイズを超えた場合にエラーが発生します。
- DataView.prototype.getUint32()
- DataView.prototype.getUint32()は、参照しているArrayBufferの指定した位置から、符号付きの32bit整数値でバイナリデータを読み込むメソッドです。読み込みの範囲が、参照しているArrayBufferのサイズを超えた場合にエラーが発生します。