JavaScript DataView.getUint16() method

The JavaScript DataView.getUint16 function is a built-in method available within the DataView object. This method is utilized for retrieving an unsigned 16-bit integer (also referred to as an unsigned short) from a designated position in the byte buffer.

Syntax

Example

dataview.getUint16(byteoffset)

Parameters

byteoffset: The number of bytes from the beginning of the view indicating the position at which to read the data.

Return value

This function yields an unsigned 16-bit integer value.

Browser Support

Chrome 9
Safari 5.1
Firefox 15
Opera 12.1

Example 1

Example

<script>

//JavaScript to illustrate dataview.getUint16() 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

arr.setUint16(1,3.1);

document.write("Convert the value 3.1 to :<br><br>");

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

//expected output: 3

</script>

Output:

Output

Convert the value 3.1 to:



3

Example 2

Example

<script>

//JavaScript to illustrate dataview.getUint16() 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.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>

Output:

Output

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



0

Example 3

Example

<script>

//JavaScript to illustrate dataview.getUint16() 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

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>

Output:

Output

convert the PI value 3.14 to:



3

Example 4

Example

<script>

//JavaScript to illustrate dataview.getUint16() method

// creating a ArrayBuffer 

var pyVisualizer = new ArrayBuffer(8);

// creating a view

var arr = new DataView(pyVisualizer);

// 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>

Output:

Output

If we give an Integer value then Output will Integer be



40

Input Required

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