goProject/.svn/pristine/ea/eaf7c0a9c2313a6abe2a388f97c0cb700658ce2d.svn-base

51 lines
1.2 KiB
Plaintext
Raw Normal View History

2025-01-06 16:21:36 +08:00
package intAndBytesUtil
import (
"bytes"
"encoding/binary"
)
// 整形转换成字节(无效,因为系统无法判断读取的字节数)
// nint型数字
// order大、小端的枚举
// 返回值:对应的字节数组
// func IntToBytes(n int, order binary.ByteOrder) []byte {
// bytesBuffer := bytes.NewBuffer([]byte{})
// binary.Write(bytesBuffer, order, n)
// return bytesBuffer.Bytes()
// }
// 整形转换成字节
// nint16型数字
// order大、小端的枚举
// 返回值:对应的字节数组
func Int16ToBytes(n int16, order binary.ByteOrder) []byte {
bytesBuffer := bytes.NewBuffer([]byte{})
binary.Write(bytesBuffer, order, n)
return bytesBuffer.Bytes()
}
// 整形转换成字节
// nint32型数字
// order大、小端的枚举
// 返回值:对应的字节数组
func Int32ToBytes(n int32, order binary.ByteOrder) []byte {
bytesBuffer := bytes.NewBuffer([]byte{})
binary.Write(bytesBuffer, order, n)
return bytesBuffer.Bytes()
}
// 整形转换成字节
// nint64型数字
// order大、小端的枚举
// 返回值:对应的字节数组
func Int64ToBytes(n int64, order binary.ByteOrder) []byte {
bytesBuffer := bytes.NewBuffer([]byte{})
binary.Write(bytesBuffer, order, n)
return bytesBuffer.Bytes()
}