Created
November 14, 2014 19:03
-
-
Save macu/c7f25960a8a7ffaef03e to your computer and use it in GitHub Desktop.
Hex dump NSData to String
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
// 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