我正在尝试将固定大小的数组 [32]byte
转换为可变大小的数组(切片)[]byte
:
package main
import (
"fmt"
)
func main() {
var a [32]byte
b := []byte(a)
fmt.Println(" %x", b)
}
但编译器抛出了错误:
./test.go:9: cannot convert a (type [32]byte) to type []byte
我应该如何转换它?
append
,它将在需要时通过重新分配来增长。 - Rick-777