Skip to content

Instantly share code, notes, and snippets.

@caelifer
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caelifer/2363f95b857dd9274cb9 to your computer and use it in GitHub Desktop.
Save caelifer/2363f95b857dd9274cb9 to your computer and use it in GitHub Desktop.
// 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)
}
@caelifer
Copy link
Author

A full working program @The Go Playground

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment