JavaScript DataView.getInt16() method

The DataView.getInt16 function in JavaScript is a built-in method associated with the DataView object. This method is utilized for retrieving a signed 16-bit integer (short) value from a designated position within the DataView.

NOTE: Range of 16-bit integer value is from 0 and 65,535 for unsigned and from ?32,768 to 32,767 for signed integer value.

Syntax

Example

dataview.getInt16(byteOffset)

Parameters

byteoffset: The position, measured in bytes, from the beginning of the view at which the data should be read.

Return value

This function yields a signed integer value that is 16 bits in length.

Browser Support

Chrome 9
Safari 5.1
Firefox 15
Opera 12.1

Example 1

Example

<script>

//JavaScript to illustrate dataview.getInt16() method

// creating a ArrayBuffer 

var pyVisualizer = new ArrayBuffer(8);

// creating a view

var arr = new DataView(pyVisualizer);

// put the value 3.1 at slot 1

document.write("If we give a float value then output will be an Integer<br><br>");

arr.setInt16(1,3.1);

document.write(arr.getInt16(1));

//expected output:3

</script>

Output:

Output

If we give a float value then output will be an Integer



3

Example 2

Example

<script>

//JavaScript to illustrate dataview.getInt16() method

// if there is no data to be stored then it returns Nan

// creating a ArrayBuffer 

var pyVisualizer = new ArrayBuffer(8);

// creating a view

var arr = new DataView(pyVisualizer);

// NO Data

arr.getInt16(1);

document.write(" If  there is no data to be stored, then Output will Be:<br><br>")

document.write(arr.getInt16(1));

//expected output:0

</script>

Output:

Output

If there is no data to be stored, then Output will Be:



0

Example 3

Example

<script>

//JavaScript to illustrate dataview.getInt16() method

// creating a ArrayBuffer 

var pyVisualizer = new ArrayBuffer(8);

// creating a view

var arr = new DataView(pyVisualizer);

//We can also use math function like Math.PI

document.write("PI value will be <br><br>");

arr.setInt16(1,Math.PI);

document.write(arr.getInt16(1));

//expected output: 3

</script>

Output:

Output

PI value will be 



3

Example 4

Example

<script>

//JavaScript to illustrate dataview.getInt16() method

// creating a ArrayBuffer 

var pyVisualizer = new ArrayBuffer(8);

// creating a view

var arr = new DataView(pyVisualizer);

// put the value 7 at slot 1

arr.setInt16(1,7);

document.write("If we provide Integer value then output will be<br><br>")

document.write(arr.getInt16(1));

//expected output: 7

</script>

Output:

Output

If we provide Integer value then output will be.



7

Input Required

This code uses input(). Please provide values below: