我想將一個緩衝區寫入一個數組,然後使用Float64Array視圖訪問該數組。這似乎比它應該更加困難。我已經使用了mozilla文檔,但仍然存在問題....在DataView中存儲緩衝區,然後使用Float64Array解壓縮
我嘗試了以下多種變體。有誰知道爲什麼這不起作用?最後我應該能夠打印出第一條浮法這是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