rename getUint32 to getInt32 and collect readInt*() in util.js

This commit is contained in:
fkaelberer 2014-04-16 21:31:16 +02:00
parent b33f4adf88
commit b06c10cbbd
6 changed files with 50 additions and 72 deletions

View file

@ -423,6 +423,28 @@ function string32(value) {
(value >> 8) & 0xff, value & 0xff);
}
function log2(x) {
var n = 1, i = 0;
while (x > n) {
n <<= 1;
i++;
}
return i;
}
function readInt8(data, start) {
return (data[start] << 24) >> 24;
}
function readUint16(data, offset) {
return (data[offset] << 8) | data[offset + 1];
}
function readUint32(data, offset) {
return ((data[offset] << 24) | (data[offset + 1] << 16) |
(data[offset + 2] << 8) | data[offset + 3]) >>> 0;
}
// Lazy test the endianness of the platform
// NOTE: This will be 'true' for simulated TypedArrays
function isLittleEndian() {