j.a. :
It exists in array form as Uint32Array ( signed version is Int32Array ), but I was told that once you access this value it becomes a normal JS number.
let number = (new Unit32Array(1)).fill(1)[0];
Where the variable number is implemented as a double and once you do a bitwise operation it is converted to a 32 bit signed integer.
I don't get the purpose of Unit32Array if you can actually use the un-signed representation in the array, i.e. once you access it, it pops out at a normal number?
function analyze () {
// let test = 2147483647; // max 32 bit integer
// let test = -2147483647; // min 32 bit integer
for(let place = 0; place < 32; place++){
let power2 = Math.pow(2, place);
let bit = test & power2;
console.log(place, bit)
}
}
analyze();
/*
2^0 is 1 is 0x1
2^1 is 2
2^2 is 4
2^3 is 8
.
.
2^31 is 2147483648
2^32 is 4294967296
*/
bob :
Most people are not aware that JavaScript works well with bit-wise operations. You need to pair it with an array buffer however.
let buffer = new ArrayBuffer(16); // create a buffer of length 16
let view = new Uint32Array(buffer); // treat buffer as a sequence of 32-bit integers