dataView.getUint32()是dataView中的內置函數,用於在指定位置(即,從dataView的起始位置開始的字節偏移)獲取無符號的32位整數。
用法:
dataView.getUint32(byteOffset)
參數:它具有參數byteOffset,該參數在字節中偏移,即從讀取數據的視圖開始處偏移。
返回值:它返回一個無符號的32位整數。
JavaScript代碼顯示此方法的用法原理:
示例1:
<script>
// Creating buffer with size in byte
var buffer = new ArrayBuffer(20);
// Creating a view
var dataview1 = new DataView(buffer, 0, 10);
// put the data 56 at slot 1
dataview1.setUint32(1, 56);
document.write(dataview1.getUint32(1) + "<br>");
</script>
輸出:
56
示例2:
此函數將PI格式3.14的浮點值轉換為3
<script>
// Creating buffer with size in byte
var buffer = new ArrayBuffer(20);
// Creating a view with slot from o to 10
var dataview1 = new DataView(buffer, 0, 10);
// put the value of PI at slot 1
dataview1.setUint32(1, Math.PI);
document.write(dataview1.getUint32(1) + "<br>");
</script>
輸出:
3
示例3:
如果沒有要存儲的數據,則返回零(0)。
<script>
// Creating buffer with size in byte
var buffer = new ArrayBuffer(20);
// Creating a view
var dataview1 = new DataView(buffer, 0, 10);
// putting no data at slot 1
dataview1.setUint32(1);
document.write(dataview1.getUint32(1) + "<br>");
</script>
輸出:
0
注:本文由純淨天空篩選整理自ShivamKD大神的英文原創作品 JavaScript | dataView.getUint32()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。