Swift convert HexString to Integer

Viewed 3114

I have a data source in String example

HexString = "72AE"

and i would like to convert it into byte and store into byte array

bytearray = [72, AE]  //UInt8

i know i can do this by

let hexaString = "72AE"
let resultArray = hexaString.characters.map{Int(strtoul(( String($0)), nil, 16))}

print(resultArray)  // "[7, 2, 10, 14]"

but it is not returning the value i want. I have also tried to chop it into hexaString1 = "72" hexaString2 = "AE" but still i can't manage to get the correct value.

1 Answers
Related