2017-08-07 100 views

回答

1

你可以適應的T.J. Crowder優異answer並使用DataView#setUint8對於給定的字節。

var data = [170, 85, 255, 63, 205, 171, 170, 85]; 
 

 
// Create a buffer 
 
var buf = new ArrayBuffer(8); 
 
// Create a data view of it 
 
var view = new DataView(buf); 
 

 
// set bytes 
 
data.forEach(function (b, i) { 
 
    view.setUint8(i, b); 
 
}); 
 

 
// Read the bits as a float 
 
var num = view.getFloat64(0); 
 
// Done 
 
console.log(num);

+0

由於龔如心,那真是棒極了! – Chuender

相關問題