Convert an integer to a byte array

前端 未结 5 1205
北荒
北荒 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条回答
  •  日久生厌
    2020-12-04 21:50

    What's wrong with converting it to a string?

    []byte(fmt.Sprintf("%d", myint))
    

提交回复
热议问题