Skip to content

Instantly share code, notes, and snippets.

@marcgeld
Last active April 3, 2019 22:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcgeld/82dad51721df7938d185e2ad5bbfe26e to your computer and use it in GitHub Desktop.
Save marcgeld/82dad51721df7938d185e2ad5bbfe26e to your computer and use it in GitHub Desktop.
make a hex String from a UInt8 collection
// Array of [UInt8] to hex String extension
// let arr = [0x03, 0x00, 0x02, 0x05, 0x11, 0x25, 0xa0, 0xfe, 0xe5] as [UInt8]
// let hex = arr.hexValueString (hex is the result)
extension Collection where Element == UInt8 {
var hexValueString: String {
return map{ String(format: "0x%02x", $0) }.joined(separator: ", ")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment