Skip to content

Instantly share code, notes, and snippets.

@SteveTrewick
Last active January 5, 2025 23:34
Show Gist options
  • Select an option

  • Save SteveTrewick/5935e7c00e22cfb87e004c1ef8b7efd5 to your computer and use it in GitHub Desktop.

Select an option

Save SteveTrewick/5935e7c00e22cfb87e004c1ef8b7efd5 to your computer and use it in GitHub Desktop.
hex bytes of swift int in memory order (LSB->MSB)
// hex bytes of swift int in memory order (LSB->MSB)
func memhex<T: BinaryInteger>(_ value: T) -> String {
var value = value
var hex = ""
withUnsafeBytes(of: &value) { bytes in
for byte in bytes {
hex += String(format:"%02x", byte) + " "
}
}
return hex
}
/*
print( memhex( UInt( 0xDEADBEEF )))
ef be ad de 00 00 00 00
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment