go语言之整形和字节数组的转换
//整形转换成字节 func IntToBytes(n int) []byte { tmp := int32(n) bytesBuffer := bytes.NewBuffer([]byte{}) binary.Write(bytesBuffer, binary.BigEndian, <span style="font-family: Arial, Helvetica, sans-serif;">tmp</span>) return bytesBuffer.Bytes() } //字节转换成整形 func BytesToInt(b []byte) int { bytesBuffer := bytes.NewBuffer(b) var tmp int32 binary.Read(bytesBuffer, binary.BigEndian, &tmp) return int(tmp) }
有疑问加站长微信联系(非本文作者)