floating point conversion - How to convert Uint8Array to a float in javascript? - Stack Overflow

I have an ArrayBuffer that I convert to a Uint8Array so that I can use traditional array access with sq

I have an ArrayBuffer that I convert to a Uint8Array so that I can use traditional array access with square brackets and gather a subarray. Now that I have the correct set of 4 bytes that describe the 32-bit (little endian) floating point number, I don't seem to have an easy way to convert to the 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 to JavaScript and am still looking around different docs...

I have an ArrayBuffer that I convert to a Uint8Array so that I can use traditional array access with square brackets and gather a subarray. Now that I have the correct set of 4 bytes that describe the 32-bit (little endian) floating point number, I don't seem to have an easy way to convert to the 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 to JavaScript and am still looking around different docs...

Share Improve this question asked Oct 3, 2014 at 22:35 tarabytetarabyte 19.3k16 gold badges86 silver badges126 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

You can use DataView.getFloat32. First, you would create the DataView from the original ArrayBuffer (or the Uint8Array). getFloat32 takes an optional parameter that allows you to specify the endianess of the data you are reading.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744921483a4601160.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信