JavaScript DataView.getUint16() 是 dataView 中的一个内置方法。它用于获取指定位置的无符号 16 位整数(无符号短整型)数。
用法
dataview.getUint16(byteoffset)
参数
byteoffset: 从读取数据的视图开始的偏移量,以字节为单位。
返回值
此方法返回一个无符号的 16 位整数。
浏览器支持
Chrome | 9 |
Safari | 5.1 |
Firefox | 15 |
Opera | 12.1 |
例子1
<script>
//JavaScript to illustrate dataview.getUint16() method
// creating a ArrayBuffer
var JavaTpoint = new ArrayBuffer(8);
// creating a view
var arr = new DataView(JavaTpoint);
// put the value 3.1 at slot 1
arr.setUint16(1,3.1);
document.write("Convert the value 3.1 to:<br><br>");
document.write(arr.getUint16(1));
//expected output:3
</script>
输出:
Convert the value 3.1 to: 3
例子2
<script>
//JavaScript to illustrate dataview.getUint16() 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.setUint16(1);
document.write("If there is no data to be stored, then Output will Be:<br><br>")
document.write(arr.getUint16(1));
//expected output:0
</script>
输出:
If there is no data to be stored, then Output will Be: 0
例子3
<script>
//JavaScript to illustrate dataview.getUint16() 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
arr.setUint16(1,Math.PI);
document.write("convert the PI value 3.14 to:<br><br>");
document.write(arr.getUint16(1));
//expected output:3
</script>
输出:
convert the PI value 3.14 to: 3
示例 4
<script>
//JavaScript to illustrate dataview.getUint16() method
// creating a ArrayBuffer
var JavaTpoint = new ArrayBuffer(8);
// creating a view
var arr = new DataView(JavaTpoint);
// put the value 40 at slot 1
arr.setUint16(1,40);
document.write("If we give an Integer value then Output will Integer be<br><br>");
document.write(arr.getUint16(1));
//expected output:40
</script>
输出:
If we give an Integer value then Output will Integer be 40
相关用法
- JavaScript DataView.getUint8()用法及代码示例
- JavaScript DataView.getUint32()用法及代码示例
- JavaScript DataView.getInt16()用法及代码示例
- JavaScript DataView.getInt8()用法及代码示例
- JavaScript DataView.getFloat32()用法及代码示例
- JavaScript DataView.getFloat64()用法及代码示例
- JavaScript DataView.getInt32()用法及代码示例
- JavaScript DataView.getBigUint64()用法及代码示例
- 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.getUint16() method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。