JavaScript dataView.getInt16() Method
Last Updated :
22 Dec, 2022
The Javascript dataView.getInt16() is an inbuilt function in dataView that is used to get a 16-bit integer at the specified location i.e, at byte offset from the start of the dataView. The range of 16-bit integer values is from 0 and 65,535 for unsigned and from ?32,768 to 32,767 for signed integer values.
Syntax:
dataview.getInt16(byteOffset)
Parameters: It has the parameter byteOffset which is offset in a byte and it says where to read the data from the beginning(start) of the view.
Return value: It returns a 16-bit signed integer value.
Below are examples of the dataView.getInt16() Method.
Example 1: In this example, we will see the basic use of dataView.getInt16() Method.
javascript
<script>
var buffer = new ArrayBuffer(20);
var dataview1 = new DataView(buffer, 0, 10);
dataview1.setInt16(1, 12);
console.log(dataview1.getInt16(1) );
</script>
Output:
12
Example 2: Here as it can be seen that this function does not take float value when this float value is given to this function then it converts that value to integer value.
javascript
<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.setInt16(1, 56);
console.log(dataview1.getInt16(1));
</script>
Output:
56
Example 3: Here as it can be seen that this function does not take float value when this float value is given to this function then it converts that value to integer value.
javascript
<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 4.5 at slot 1
dataview1.setInt16(1, 4.5);
console.log(dataview1.getInt16(1));
</script>
Output:
4
Example 4: When there is no data to be stored, then it returns NaN i.e, not a number.
javascript
<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.setInt16(1);
console.log(dataview1.getInt16(1));
</script>
Output:
0
We have a complete list of Javascript Functions, to check those please go through Javascript Function Complete reference article.
Supported Browsers:
- Google Chrome 9 and above
- Edge 12 and above
- Firefox 15 and above
- Internet Explorer 10 and above
- Opera 12.1 and above
- Safari 5.1 and above
Similar Reads
JavaScript dataView.getUint16() Method The dataView.getUint16() is an inbuilt function in dataView that is used to get an unsigned 16-bit integer at the specified location i.e, at byte offset from the start of the dataView. Syntax: dataView.getUint16(byteOffset) Parameters: It has the parameter byteOffset which is offset in a byte and it
2 min read
JavaScript dataView.getInt8() Method The dataView.getInt8() is a method in dataView which is used to get an 8-bit integer in the byte at the specified location from the start of the dataView. Syntax: dataview.getInt8(byteOffset) Parameters: It has the parameter byteOffset which is offset in a byte and it says from the start of the view
2 min read
JavaScript dataView.getInt32() Method The dataView.getInt32() is an inbuilt function in dataView that is used to get a 32-bit integer at the specified location i.e, at byte offset from the start of the dataView. The range of 32-bit integer value is from 0 to 4,294,967,295 for unsigned and from 2,147,483,648 to 2,147,483,647 for the sign
2 min read
JavaScript dataView.getUint8() Method The dataView.getUint8() is an inbuilt function in dataView that is used to get an unsigned 8-bit integer at the specified location i.e, at byte offset from the start of the dataView. Syntax: dataView.getUint8(byteOffset) Parameters: It has the parameter byteOffset which is offset in a byte and it sa
2 min read
JavaScript dataView.getBigInt64() method This getBigInt64() method is used to get a signed 64-bit integer (long long) at the particular byte offset from the start of the DataView. Syntax: dataview.getBigInt64(byteOffset, value, littleEndian) Parameters: byteOffset: This parameter specifies the offset, in bytes, from the start of the view t
2 min read