Created
January 28, 2019 09:25
-
-
Save 607011/c21d2df896e8504c491b27d62534f646 to your computer and use it in GitHub Desktop.
Get Endianness
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func nativeEndianness() binary.ByteOrder { | |
buf := [2]byte{} | |
*(*uint16)(unsafe.Pointer(&buf[0])) = uint16(0xabcd) | |
switch buf { | |
case [2]byte{0xcd, 0xab}: | |
return binary.LittleEndian | |
case [2]byte{0xab, 0xcd}: | |
return binary.BigEndian | |
default: | |
panic("Could not determine native endianness.") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment