mirror of
https://github.com/Monibuca/engine.git
synced 2025-10-07 01:22:51 +08:00
4.0初步改造
This commit is contained in:
17
util/big_endian.go
Normal file
17
util/big_endian.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package util
|
||||
|
||||
import "constraints"
|
||||
|
||||
func PutBE[T constraints.Integer](b []byte, num T) []byte {
|
||||
for i, n := 0, len(b); i < n; i++ {
|
||||
b[i] = byte(num >> ((n - i - 1) << 3))
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func ReadBE[T constraints.Integer](b []byte) (num T) {
|
||||
for i, n := 0, len(b); i < n; i++ {
|
||||
num += T(b[i]) << ((n - i - 1) << 3)
|
||||
}
|
||||
return
|
||||
}
|
Reference in New Issue
Block a user