Skip to content

Instantly share code, notes, and snippets.

@petergi
Created December 29, 2023 06:25
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 petergi/9be29180d6b7aa1e776a20f9377062eb to your computer and use it in GitHub Desktop.
Save petergi/9be29180d6b7aa1e776a20f9377062eb to your computer and use it in GitHub Desktop.
Convert hex to ASCII
let asciiValue: String = "1234567890ABCDEFGHIJ"
func asciiToHex(_ asciiValue: String) -> String {
let chars: [String.Element] = Array(asciiValue)
var hex: String = ""
for char: String.Element in chars {
hex += String(char.asciiValue!, radix: 16)
}
return hex
}
let result = asciiToHex(asciiValue)
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment