Created
June 19, 2014 05:36
-
-
Save jtbandes/b5f9a8889b6617da4c03 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
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