import (
"bytes"
"encoding/binary"
"encoding/gob"
"fmt"
)
func str_to_byte(src string) []byte {
//strSlice := []string{src}
buffer := &bytes.Buffer{}
gob.NewEncoder(buffer).Encode(src)
return buffer.Bytes()
}
func uint64_to_byte(src uint64) []byte {
buf := make([]byte, 8)
binary.BigEndian.PutUint64(buf, src)
return buf
}
func main() {
var u uint64
u = 128
bytes := uint64_to_byte(u)
fmt.Println(bytes)
str := "128"
bytes = str_to_byte(str)
fmt.Println(bytes)
}
原文地址:https://www.cnblogs.com/chris-cp/p/9101656.html
时间: 2024-10-14 02:15:03