Last active
January 5, 2025 23:34
-
-
Save SteveTrewick/5935e7c00e22cfb87e004c1ef8b7efd5 to your computer and use it in GitHub Desktop.
hex bytes of swift int in memory order (LSB->MSB)
This file contains hidden or 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
| // 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