JavaScript DataView.getInt8() 是 dataView 中的一個內置方法。它用於在指定位置獲取有符號的 8 位整數(字節)數。
用法
dataview.getInt8(byteOffset)
參數
byteoffset: 從讀取數據的視圖開始的偏移量,以字節為單位。
返回值
此方法返回一個有符號的 8 位整數。
瀏覽器支持
Chrome | 9 |
Safari | 5.1 |
Firefox | 15 |
Opera | 12.1 |
例子1
<script>
//JavaScript to illustrate dataview.getInt8() method
// creating a ArrayBuffer
var JavaTpoint = new ArrayBuffer(8);
// creating a view
var arr = new DataView(JavaTpoint);
// put the value 6.1 at slot 1
document.write("If we give a float value, the output will be an Integer<br><br>");
arr.setInt8(1,6.1);
document.write(arr.getInt8(1));
//expected output:6
</script>
輸出:
If we give a float value, the output will be an Integer 6
例子2
<script>
//JavaScript to illustrate dataview.getInt8() method
// if there is no data to be stored then it returns Nan
// creating a ArrayBuffer
var JavaTpoint = new ArrayBuffer(8);
// creating a view
var arr = new DataView(JavaTpoint);
// NO Data
arr.getInt8(1);
document.write(" If there is no data to be stored, then Output will Be 0:<br><br>")
document.write(arr.getInt8(1));
//expected output:0
</script>
輸出:
If there is no data to be stored, then Output will Be: 0
例子3
<script>
//JavaScript to illustrate dataview.getInt8() method
// creating a ArrayBuffer
var JavaTpoint = new ArrayBuffer(8);
// creating a view
var arr = new DataView(JavaTpoint);
//We can also use math function like Math.PI
document.write("PI value<br><br>");
arr.setInt8(1,Math.PI);
document.write(arr.getInt8(1));
//expected output:3
</script>
輸出:
PI value 3
示例 4
<script>
//JavaScript to illustrate dataview.getInt8() method
// creating a ArrayBuffer
var JavaTpoint = new ArrayBuffer(8);
// creating a view
var arr = new DataView(JavaTpoint);
// put the value 19 at slot 1
arr.setInt8(1,19);
document.write("If we give an Integer value then Output will be Integer<br><br>");
document.write(arr.getInt8(1));
//expected output:19
</script>
輸出:
If we give an Integer value then Output will be Integer 19
相關用法
- JavaScript DataView.getInt16()用法及代碼示例
- JavaScript DataView.getInt32()用法及代碼示例
- JavaScript DataView.getFloat32()用法及代碼示例
- JavaScript DataView.getUint8()用法及代碼示例
- JavaScript DataView.getFloat64()用法及代碼示例
- JavaScript DataView.getBigUint64()用法及代碼示例
- JavaScript DataView.getUint32()用法及代碼示例
- JavaScript DataView.getUint16()用法及代碼示例
- JavaScript DataView.setBigUint64()用法及代碼示例
- JavaScript Date toISOString()用法及代碼示例
- JavaScript Date getUTCFullYear()用法及代碼示例
- JavaScript Date toJSON()用法及代碼示例
- JavaScript Date toLocaleTimeString()用法及代碼示例
- JavaScript Date setMinutes()用法及代碼示例
- JavaScript Date getMinutes()用法及代碼示例
- JavaScript Date getUTCHours()用法及代碼示例
- JavaScript Date now()用法及代碼示例
- JavaScript Date UTC()用法及代碼示例
- JavaScript Date setDate()用法及代碼示例
- JavaScript Date setMilliseconds()用法及代碼示例
注:本文由純淨天空篩選整理自 JavaScript DataView.getInt8() method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。