I have a slice consisting of 3 bytes (ordered in LE) that is representing a signed integer, and I want to convert it to any of the integer types, preferably int32, and then back to itself.
b := []byte{0x01, 0x00, 0x80}
I tried to do that using big.Int, but it seemed like its SetBytes() and Bytes() methods only work for unsigned integer types, regardless of that a big.Int instance can also store signed integer types.
Here is a Python equivalent of what I’m trying to do:
b = b"\x01\x00\x80"
i = int.from_bytes(b, "little", signed=True)
b_again = int.to_bytes("little", signed=True)
Edit: This question is not a duplicate of Go []byte to Little/Big-Endian Signed Integer or Float?. I have tried applying the answers there, but their results weren’t expected. See my first comment.
https://go.dev/play/p/tI8E2kSXopZ