JavaScript dataView.getInt16() Method

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>     varbuffer = newArrayBuffer(20);      vardataview1 = newDataView(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     varbuffer = newArrayBuffer(20);          // Creating a view     vardataview1 = newDataView(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     varbuffer = newArrayBuffer(20);          // Creating a view with slot from o to 10     vardataview1 = newDataView(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     varbuffer = newArrayBuffer(20);          // Creating a view     vardataview1 = newDataView(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
 
				 
					


