I want to write a buffer into an array and then access that array with the Float64Array view. This seems to be a lot more difficult than it should. I have used the mozilla documentation but still having problems....
I have tried multiple variants of below. Does anyone know why this is not working? At the end I should be able to print out the first float which is 4.
//64 bit floating point numbers with 8 bytes each in hex
//first float64 bytes : 4 = 0x4010000000000000
//second float64 bytes : 5 = 0x4014000000000000
//2 x 8 bytes in a buffer with each hex number
var buff = new Buffer("40100000000000004014000000000000", "hex");
var ab = new ArrayBuffer(buff.length);
var view = new DataView(ab);
for (var i = 0; i < buff.length; ++i) {
view[i] = buff[i];
}
console.log(new Float64Array(ab).length);//prints 2
console.log(new Float64Array(ab)[0]);// SHOULD print '4' but prints 0