Convert an integer to a byte array

前端 未结 5 1211
北荒
北荒 2020-12-04 21:11

I have a function which receives a []byte but I what I have is an int, what is the best way to go about this conversion?

err = a.Wr         


        
5条回答
  •  旧时难觅i
    2020-12-04 21:50

    Check out the "encoding/binary" package. Particularly the Read and Write functions:

    binary.Write(a, binary.LittleEndian, myInt)
    

提交回复
热议问题