Skip to content

Instantly share code, notes, and snippets.

@macu
Created November 14, 2014 19:03
Show Gist options
  • Save macu/c7f25960a8a7ffaef03e to your computer and use it in GitHub Desktop.
Save macu/c7f25960a8a7ffaef03e to your computer and use it in GitHub Desktop.
Hex dump NSData to String
// Thanks http://www.swiftsoda.com/swift-coding/get-bytes-from-nsdata/
func hexDump(data: NSData) -> String {
var len = data.length
var s = NSMutableString(capacity: len*2)
var byteArray = [UInt8](count: len, repeatedValue: 0x0)
data.getBytes(&byteArray, length:len)
for v in byteArray {
s.appendFormat("%02x", v)
}
return s
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment