I'm trying to convert a int16 to a byte array but i cant seem to get it to work.
Here is what i've got right now:
int16 i := 41
a := []byte(string(i))//this line is wrong
如果有人想知道数组的长度是否需要为2.
I'm trying to convert a int16 to a byte array but i cant seem to get it to work.
Here is what i've got right now:
int16 i := 41
a := []byte(string(i))//this line is wrong
如果有人想知道数组的长度是否需要为2.
如果要获取int16的字节,请try 以下操作:
var i int16 = 41
var h, l uint8 = uint8(i>>8), uint8(i&0xff)
Go试图使编写依赖于您的平台属性(如字节顺序)的程序变得困难.因此,禁止导致这种依赖关系的类型双关(例如用int16覆盖字节数组).
如果你真的想搬起石头砸自己的脚,试试unsafe号套餐吧.