The DataView view in JavaScript provides an interface to read and write multiple number types into an
JavaScript’s dataView.getInt32()
is a built-in method in dataView.
dataView.getInt32()
gets a signed 32-bit integer from the start of the dataView
number at a specified offset.
dataView.getInt32()
is declared as shown below:
dataview.getInt32()
takes the following two parameters:
byteOffset
- compulsory parameter that represents the offset, in bytes, from the start of the view from where to read the data.
littleEndian
- optional parameter that indicates if the 32-bit integer should be stored in little or big-endian notation. If littleEndian
is True
, the value is read in little-endian format. If it is False
or not specified, the value is read in big-endian format.
The dataView.getInt32()
method returns a 32-bit signed integer value.
If
byteOffset
is set such that it would read beyond the end of the view, then aRangeError
occurs.
The example below shows the use of the dataView.getInt32()
method in JavaScript when the second parameter is not specified:
//Create ArrayBuffervar buf = new ArrayBuffer(16);//Declare DataViewconst dataview = new DataView(buf);dataview.setInt32(1,1234556789);//Call getInt32 methodconsole.log(dataview.getInt32(1));
The example below shows the use of the dataView.getInt32()
method in JavaScript when the second parameter is specified:
//Create ArrayBuffervar buf = new ArrayBuffer(16);//Declare DataViewconst dataview = new DataView(buf);dataview.setInt32(1,1234556789);//Call getInt32 methodconsole.log(dataview.getInt32(1, littleEndian = true));
Free Resources