[Solved] Golang – Add int to end of byte array


You want a space-padded ascii representation of a number as bytes? fmt.Sprintf produces a string, which you can then convert to bytes.

Here’s some code, or run it on the playground.

package main

import "fmt"

func main() {
    bs := []byte(fmt.Sprintf("%2d", 7))
    fmt.Println(bs)
}

0

solved Golang – Add int to end of byte array