I have a variable Uint8Arr of type Uint8Array[4].
Uint8Arr[0]=0x12;
Uint8Arr[1]=0x19;
Uint8Arr[2]=0x21;
Uint8Arr[3]=0x47;
I want to convert Uint8Arr into its equivalent integer which is 0x12192147 or 303636807.
I would like to have a function that can convert Uint8Arr[n] into its equivalent integer and return the result in decimal.
For those who want little-endian, you can specify endianness using the DataView class.
let buff = new Uint8Array(4);
buff[0]=0x12;
buff[1]=0x19;
buff[2]=0x21;
buff[3]=0x47;
var view = new DataView(buff.buffer, 0);
view.getUint32(0, true); // true here represents little-endian
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With