getInt32() reads four bytes from a DataView and returns a signed 32-bit whole number from -2147483648 to 2147483647 (about ±2.1 billion). That is enough for most counters, amounts of money in cents, or coordinates stored as whole numbers. The four bytes are read big-endian by default; pass true as the second argument when the data is little-endian.
Reads the 4 bytes starting at byteOffset in big-endian order (most significant byte first) and returns a signed whole number from -2147483648 to 2147483647.
view.getInt32(byteOffset, true)
Reads the same 4 bytes in little-endian order (least significant byte first), the order used by most file formats from PCs, such as WAV and BMP.
Part of the original DataView from ES2015, so every modern browser and runtime has it. Unlike a Int32Array, a DataView has no alignment rule: getInt32() works at any byte position, even one that is not a multiple of 4.
Library declarations
JavaScript
DataView.prototype.getInt32(byteOffset)
DataView.prototype.getInt32(byteOffset, littleEndian)
// returns a Number: -2147483648 to 2147483647
// reads 4 bytes starting at byteOffset (counted from the start of the view)
// needs byteOffset + 4 <= view.byteLength, else RangeError
// littleEndian: false or left out = big-endian
Parameters
Parameter
Description
byteOffset
Where to start reading, counted in bytes from the start of the view (not of the underlying buffer). It is converted to a whole number, so 1.9 means 1 and "2" means 2. All 4 bytes must fit: byteOffset + 4 may not be larger than view.byteLength. A negative or too-large offset throws a RangeError.
littleEndian
Optional. Leave it out (or pass false) for big-endian: the most significant of the 4 bytes comes first. Pass true for little-endian: the least significant byte comes first. Any truthy value, such as 1, also means little-endian.
Return Value
Return Value
Description
Number
A whole Number from -2147483648 to 2147483647, built from the 4 bytes at byteOffset using two’s complement for negative values.
JavaScript Examples
Example 1 — Sum a Ledger of Signed Amounts in Cents
A small ledger stores income and spending as signed 32-bit numbers of cents. Read every entry and print the balance.
JavaScript
const ledger = new DataView(new ArrayBuffer(12));
ledger.setInt32(0, 150000); // salary: +1500.00
ledger.setInt32(4, -2599); // groceries: -25.99
ledger.setInt32(8, -99900); // rent: -999.00
let total = 0;
for (let i = 0; i < ledger.byteLength; i += 4) {
total += ledger.getInt32(i);
}
console.log("balance: " + (total / 100).toFixed(2)); // balance: 475.01
The largest positive value. 2147483647 is 0x7fffffff: every bit is 1 except the top one, so getInt32() reads it unchanged.
One more flips the sign. 2147483648 sets only the top bit. getInt32() treats that bit as the minus sign and returns -2147483648.
See the sign bit. The first byte in binary is 10000000: in big-endian order the sign bit is the very first bit of the 4 bytes.
Compatibility
Browser & Runtime Support
getInt32() has been part of JavaScript since ES2015, when DataView itself was standardised.
✓ ES2015 · Baseline
DataView.prototype.getInt32()
Works in every modern browser and in Node.js, Deno and Bun. It runs on a normal ArrayBuffer, so no special page setup is needed.
100%Modern browser support
Google ChromeModern versions · Desktop & Mobile
Full support
Mozilla FirefoxModern versions · Desktop & Mobile
Full support
Apple SafariModern versions · macOS & iOS
Full support
Microsoft EdgeModern versions · Chromium
Full support
OperaModern versions
Full support
Samsung InternetModern versions · Android
Full support
Internet ExplorerRetired browser · not tested here
Legacy
Node.jsCurrent releases · checked on Node 24
Supported
DenoCurrent releases
Supported
BunCurrent releases
Supported
getInt32()All modern engines
Bottom line: Safe to use without a fallback. It also works on a SharedArrayBuffer, but a normal ArrayBuffer is all you need.
Frequently Asked Questions
From -2147483648 to 2147483647, which is -2 to the power 31 up to 2 to the power 31 minus 1.
The ID was stored as an unsigned value above 2147483647. Its top bit is set, which getInt32() treats as a minus sign. Read it with getUint32() instead.
No. Every 32-bit value fits safely in a normal Number, so getInt32() returns a Number. Only the 64-bit methods return BigInt.
Pass true as the second argument: view.getInt32(offset, true).
Four. offset + 4 must not be larger than the view byteLength, otherwise a RangeError is thrown.