After running this code:
var arr = new Uint32Array(16);
for (var i=0; i<16; ++i) arr[i] = i;
fs.writeFileSync("arr",new Uint8Array(arr).buffer);
console.log([].slice.call(new Uint32Array(fs.readFileSync("arr"))));
The expected output is:
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ]
But, instead, it produces this output:
[ 91, 111, 98, 106, 101, 99, 116, 32, 65, 114, 114, 97, 121, 66, 117, 102, 102, 101, 114, 93 ]
A hexdump of the arr
file shows this:
0000000 5b 6f 62 6a 65 63 74 20 41 72 72 61 79 42 75 66
0000010 66 65 72 5d
Why does the produced output not match the expected output?