gitee.com/quant1x/num@v0.3.2/binary/endian.go (about) 1 package binary 2 3 import ( 4 "encoding/binary" 5 "unsafe" 6 ) 7 8 var ( 9 IsLittleEndian = defaultEndian() // 是否小端字节序, go默认是小端 10 ) 11 12 // defaultEndian 字节存储次序 13 func defaultEndian() bool { 14 var value int32 = 0x01020304 15 // 大端(16进制): 01 02 03 04 16 // 小端(16进制): 04 03 02 01 17 pointer := unsafe.Pointer(&value) 18 pb := (*byte)(pointer) 19 b := *pb 20 if b == 0x04 { 21 return true 22 } 23 return false 24 } 25 26 func defaultByteOrder() binary.ByteOrder { 27 return binary.NativeEndian 28 }