Last active
August 29, 2015 14:26
-
-
Save caelifer/2363f95b857dd9274cb9 to your computer and use it in GitHub Desktop.
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
// Swap bytes routines (hi <-> lo) for uint8, uint16, uint32 and uint64 | |
func swapbytes8(d uint8) uint8 { | |
return (d << 4) | (d >> 4) | |
} | |
func swapbytes16(d uint16) uint16 { | |
return (d << 8) | (d >> 8) | |
} | |
func swapbytes32(d uint32) uint32 { | |
return (d << 16) | (d >> 16) | |
} | |
func swapbytes64(d uint64) uint64 { | |
return (d << 32) | (d >> 32) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A full working program @The Go Playground