I have a 16-bit in a string but this is the representation of a signed number. Is there a way/function that do the converson from signed bits to decimal ?
The function tonumber() assumes the bits are unsigned.
I have a 16-bit in a string but this is the representation of a signed number. Is there a way/function that do the converson from signed bits to decimal ?
The function tonumber() assumes the bits are unsigned.
Copyright © 2021 Jogjafile Inc.
Lua 5.3/5.4
Use
string.unpackwith a format string<i2to read the binary string. (use>i2for big endian data)Lua 5.2/5.1
There is no
string.unpack, so you have to read each byte of the string, then compute the value manually.