I want to convert bytes of a big-endian signed integer into big.Int
. In python I would do it this way:
>>> int.from_bytes(b'\xfc\x00', byteorder='big', signed=False)
64512
>>> int.from_bytes(b'\xfc\x00', byteorder='big', signed=True) # <- I want this functionality
-1024
In Go, I'm able to do it only with unsigned integers this way:
blob := "\xfc\x00"
fmt.Printf("output: %#v\n", big.NewInt(0).SetBytes([]byte(blob)).String())
// output: "64512"
with this particular example how do I get a big.Int with value of -1024
?
Update
the answer suggested by @jakub, doesn't work for me because binary.BigEndian.Uint64
converts to unsigned int, and I need a signed integer.