goProject/trunk/goutil/intAndBytesUtil/bytes.go
皮蛋13361098506 1b77f62820 初始化项目
2025-01-06 16:01:02 +08:00

59 lines
1.2 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package intAndBytesUtil
import (
"bytes"
"encoding/binary"
)
// 字节数组转换成整形
// b字节数组
// order大、小端的枚举
// 返回值对应的int值
func BytesToInt(b []byte, order binary.ByteOrder) int {
bytesBuffer := bytes.NewBuffer(b)
var result int
binary.Read(bytesBuffer, order, &result)
return result
}
// 字节数组转换成整形
// b字节数组
// order大、小端的枚举
// 返回值对应的int16值
func BytesToInt16(b []byte, order binary.ByteOrder) int16 {
bytesBuffer := bytes.NewBuffer(b)
var result int16
binary.Read(bytesBuffer, order, &result)
return result
}
// 字节数组转换成整形
// b字节数组
// order大、小端的枚举
// 返回值对应的int32值
func BytesToInt32(b []byte, order binary.ByteOrder) int32 {
bytesBuffer := bytes.NewBuffer(b)
var result int32
binary.Read(bytesBuffer, order, &result)
return result
}
// 字节数组转换成整形
// b字节数组
// order大、小端的枚举
// 返回值对应的int64值
func BytesToInt64(b []byte, order binary.ByteOrder) int64 {
bytesBuffer := bytes.NewBuffer(b)
var result int64
binary.Read(bytesBuffer, order, &result)
return result
}