Although JavaScript may not accurately represent all 64-bit integer numbers, it can handle numbers larger than 32 bits, which is what I am looking for. I need JavaScript to provide me with whatever level of precision it can offer.
I have a byte array of a specified length, ranging from 1 to 16 bytes, containing either a signed or unsigned integer in big-endian format (network byte order).
How can I extract the numerical value from this byte array?
Existing solutions often fail when dealing with negative numbers, and tools like DataView are limited to 32 bits. I am seeking an elegant, simple, and efficient pure JavaScript solution to address this issue. Unfortunately, I have not found a suitable solution within the visible web resources.
For reference, here is my implementation for handling positive numbers:
function readInt(array) {
var value = 0;
for (var i = array.length - 1; i >= 0; i--) {
value = (value * 256) + array[i];
}
return value;
}