floating point conversion - How to convert Uint8Array to a float in javascript? -
i have arraybuffer
convert uint8array
can utilize traditional array access square brackets , gather subarray. have right set of 4 bytes describe 32-bit (little endian) floating point number, don't seem have easy way convert floating point value:
var startindex = 2; var buffer = new uint8array(data) buffer.subarray(startindex, startindex + 4); var mynumber = ?uint8arraytofloat(buffer); console.log(mynumber);
i'm new javascript , still looking around different docs...
you can utilize dataview.getfloat32
. first, create dataview
original arraybuffer
(or uint8array
). getfloat32 takes optional parameter allows specify endianess of info reading.
javascript floating-point-conversion
No comments:
Post a Comment