Skip to content

Instantly share code, notes, and snippets.

@telliott99
Created December 7, 2015 17:48
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 telliott99/6c4353118672e8b775e6 to your computer and use it in GitHub Desktop.
Save telliott99/6c4353118672e8b775e6 to your computer and use it in GitHub Desktop.
Dictionary to go from a String like "ff" to a UInt8 like 255
func dictionaryBytesToInts() -> [String:UInt8] {
var D: [String:UInt8] = [:]
let chars = "0123456789abcdef".characters.map { String($0) }
for k1 in chars {
for k2 in chars {
let i = chars.indexOf(k1)!
let j = chars.indexOf(k2)!
D[k1+k2] = UInt8(i*16 + j)
}
}
return D
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment