SYNCERのロゴ
アイキャッチ画像

DataView.prototype.getUint32() - 符号付き32bit整数値で読み込む

DataView.prototype.getUint32()は、参照しているArrayBufferの指定した位置から、符号付きの32bit整数値でバイナリデータを読み込むメソッドです。読み込みの範囲が、参照しているArrayBufferのサイズを超えた場合にエラーが発生します。

概要

名前
getUint32
所属
DataView.prototype
仕様書
https://tc39.github.io/ecma262/#sec-dataview.prototype.getuint32

説明

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>

サポート状況

ChromeFirefoxSafariEdgeIEOperaiOS SafariAndroid
15+ 5.1+ 10+ 11.6+ 4.0+
  • Twitterでシェア
  • Facebookでシェア
  • Google+でシェア
  • はてなブックマークでシェア
  • pocketに保存
  • LINEでシェア
更新履歴
2017年9月30日 (土)
コンテンツを公開しました。