Skip to content

Instantly share code, notes, and snippets.

@ha1f
Created March 16, 2021 05:36
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 ha1f/d2ec69acc92c079dbe0b8b5fd5b1ee25 to your computer and use it in GitHub Desktop.
Save ha1f/d2ec69acc92c079dbe0b8b5fd5b1ee25 to your computer and use it in GitHub Desktop.
private func _hexString<I: BinaryInteger>(_ value: I) -> String {
"0x" + String(value, radix: 16)
}
extension Character {
func hexRepresentation() -> String {
unicodeScalars
.map { _hexString($0.value) }
.joined(separator: ", ")
}
}
extension StringProtocol {
func hexRepresentation() -> String {
unicodeScalars
.map { _hexString($0.value) }
.joined(separator: ", ")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment