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

51 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"
)
// 整形转换成字节(无效,因为系统无法判断读取的字节数)
// 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()
}