将[]byte转换成负整数

FreeWong · · 1024 次点击
s := []byte{0xd6} reader := bytes.NewReader(s) var a int8 if err := binary.Read(reader, binary.LittleEndian, &a); err != nil { log.Fatal(err) } fmt.Println(a)
#3
更多评论
``` package main import ( "fmt" "unsafe" ) func main() { s := []byte{0xd6} var b8 int8 b8 = *((*int8)(unsafe.Pointer(&s[0]))) fmt.Println(b8) } ```
#1
s := []byte{0xd6} fmt.Println(int8(s[0]))
#2