I see some answers to exactly the same question I have: How to convert Byte array to int in GO programming language?
I wrote below function to convert byte array to int
func convertByteToInt(in []byte) int32 {
return (int32(in[0]) << 24 | int32(in[1]) << 16 | int32(in[2]) << 8 | int32(in[3]))
}
Before that, I made sure that byte array has correct(base 256) values. in[0] = 54 (ASCII for 6), in[1] = 54 (ASCII for 6), in[2] = 49 (ASCII for 1), in[3] = 49 (ASCII for 1).
So I am expecting to retrieve integer 6611 value from byte array, but I ended up getting 909521201. I fail to understand what is exactly going on in such a simple conversion. Can anyone flash some light?
THanks