JavaScript DataView.getUint8() method

The DataView.getUint8 method in JavaScript is a built-in function that retrieves an unsigned 8-bit integer (also known as an unsigned byte) from a designated position within the DataView.

Syntax

Example

dataview.getUint8(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 an unsigned 8-bit integer value.

Browser Support

Chrome 9
Safari 5.1
Firefox 15
Opera 12.1

Example 1

Example

<script>

//JavaScript to illustrate dataview.getUint8() method

// creating a ArrayBuffer 

var pyVisualizer = new ArrayBuffer(8);

// creating a view

var arr = new DataView(pyVisualizer);

// put the value 33.4 at slot 1

arr.setUint8(1,33.4);

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

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

//expected output: 33

</script>

Output:

Output

Convert the Float value 33.4 to:



33

Example 2

Example

<script>

//JavaScript to illustrate dataview.getUint8() method

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

// creating a ArrayBuffer 

var pyVisualizer = new ArrayBuffer(10);

// creating a view

var arr = new DataView(pyVisualizer);

// NO Data

arr.setUint8(1);

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

document.write(arr.getUint8(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.getUint8() method

// creating a ArrayBuffer 

var pyVisualizer = new ArrayBuffer(10);

// creating a view

var arr = new DataView(pyVisualizer);

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

arr.setUint8(1,Math.PI);

document.write("Convert the PI value 3.14 to <br><br>");

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

//expected output: 3 

</script>

Output:

Output

Convert the PI value 3.14 to 



3

Example 4

Example

<script>

//JavaScript to illustrate dataview.getUint8() method

// creating a ArrayBuffer 

var pyVisualizer = new ArrayBuffer(10);

// creating a view

var arr = new DataView(pyVisualizer);

// put the value 67 at slot 1

arr.setUint8(1,67);

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

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

//expected output: 67

</script>

Output:

Output

If we give an Integer value then Output will be Integer



67

Input Required

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