I have an arraybuffer and I want to get double values.For example from [64, -124, 12, 0, 0, 0, 0, 0] I would get 641.5
Any ideas?
I have an arraybuffer and I want to get double values.For example from [64, -124, 12, 0, 0, 0, 0, 0] I would get 641.5
Any ideas?
Based on the answer from Nina Scholz I came up with a shorter:
function getFloat(data /* Uint8Array */) {
return new DataView(data.buffer).getFloat64(0);
}
Or if you have a large array and know the offset:
function getFloat(data, offset = 0) {
return new DataView(data.buffer, offset, 8).getFloat64(0);
}
You could adapt the excellent answer of T.J. Crowder and use
DataView#setUint8
for the given bytes.For multiple numbers, you could take chunks of 8.