Reputation: 57
How do you convert following
var data = new Uint16Array([131, 220]);
to integer
? Expected value is somewhere around 970
Upvotes: 1
Views: 631
Reputation: 386654
Basically you need to reduce the values by multiplying with 28 and cut off the first bit.
(This is not a general converting, but rather for this special purpose.)
var data = new Uint16Array([131, 220]),
value = [].reduce.call(data, function (r, a) {
return (r << 8) + a;
}, 0) & ((1 << 15) - 1);
console.log(value);
Upvotes: 1