DataView.prototype.getUint32() - 符号付き32bit整数値で読み込む
DataView.prototype.getUint32()は、参照しているArrayBufferの指定した位置から、符号付きの32bit整数値でバイナリデータを読み込むメソッドです。読み込みの範囲が、参照しているArrayBufferのサイズを超えた場合にエラーが発生します。
概要
説明
DataView.prototype.getUint32 ( byteOffset [ , littleEndian ] )
第1引数(byteOffset)には、参照しているバッファから読み込みを開始する位置をByte単位のオフセットで指定する。
第2引数(littleEndian)には、任意でデータの配置方式を指定する。trueならLittle endian、falseならBig endian。省略した場合はtrueになる。
チュートリアル
var arrayBuffer = new Uint8Array( [ 0x00, 0x00, 0x00, 0x00, 0x8f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff ] ).buffer ;
var dataView = new DataView( arrayBuffer ) ;
dataView.getUint32( 0 ) ; // 0 (0x00000000) [ 0x00, 0x00, 0x00, 0x00, 0x8f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff ]
dataView.getUint32( 4 ) ; // 2415919103 (0x8fffffff) [ 0x00, 0x00, 0x00, 0x00, 0x8f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff ]
dataView.getUint32( 8 ) ; // 4294967295 (0xffffffff) [ 0x00, 0x00, 0x00, 0x00, 0x8f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff ]
デモ
DataView.prototype.getUint32()のデモです。
<!-- このコードは編集できます。 -->
<!DOCTYPE html>
<html>
<head>
<style>
body {
white-space: pre-wrap ;
}
</style>
</head>
<body>
<script>
/** try it! **/
var arrayBuffer = new Uint8Array( [ 0x00, 0x00, 0x00, 0x00, 0x8f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff ] ).buffer ;
var dataView = new DataView( arrayBuffer ) ;
var a = dataView.getUint32( 0 ) ;
var b = dataView.getUint32( 4 ) ;
var c = dataView.getUint32( 8 ) ;
/** try it! **/
var results = { a:a, b:b, c:c, } ;
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.getUint16()
- DataView.prototype.getUint16()は、参照しているArrayBufferの指定した位置から、符号なし16bit整数値でバイナリデータを読み込むメソッドです。読み込みの範囲が、参照しているArrayBufferのサイズを超えた場合にエラーが発生します。
- DataView.prototype.getUint8()
- DataView.prototype.getUint8()は、参照しているArrayBufferの指定した位置から、符号なし8bit整数値でバイナリデータを読み込むメソッドです。読み込みの範囲が、参照しているArrayBufferのサイズを超えた場合にエラーが発生します。
- DataView
- DataViewは固定長のバイナリデータを読み書きする機能を備えたオブジェクトです。
- JSON.stringify()
- JSON.stringify()は、JSONオブジェクトを文字列に変換するメソッドです。文字列に変換する際、オブジェクトはシリアライズされます。例えば、値がnew Date()の場合、toJSON()が実行されて、JSONシリアライズした値に変換されて文字列化します。