Skip to content

Instantly share code, notes, and snippets.

@kconner
Created May 31, 2017 21:37
Show Gist options
  • Save kconner/48f3801cd9f2677b04f1154a234cbb39 to your computer and use it in GitHub Desktop.
Save kconner/48f3801cd9f2677b04f1154a234cbb39 to your computer and use it in GitHub Desktop.
Print the bytes of a Data in hexadecimal
private func printData(_ data: Data) {
let hexBytes = data.map { byte in
String(format: "%02x", byte)
}
for (offset, hexByte) in hexBytes.enumerated() {
let terminator: String
switch offset % 8 {
case 7:
terminator = "\n"
case 3:
terminator = " "
default:
terminator = " "
}
print(hexByte, terminator: terminator)
}
print()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment