Skip to content

Instantly share code, notes, and snippets.

@jtbandes
Created June 19, 2014 05:36
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 jtbandes/b5f9a8889b6617da4c03 to your computer and use it in GitHub Desktop.
Save jtbandes/b5f9a8889b6617da4c03 to your computer and use it in GitHub Desktop.
func bytes<T: UnsignedInteger>(val: T) -> GeneratorOf<UInt8> {
var current = val as UInt64
var step = 0
return GeneratorOf<UInt8> {
if step >= sizeof(T) { return nil }
current >>= 8; step++
return UInt8(current & UInt64(UInt8.max))
}
}
Array(bytes(0xABCDEF as UInt64))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment