Created
December 7, 2015 17:48
-
-
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
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
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