Hex to Decimal - Swift Hex to Decimal - Swift swift swift

Hex to Decimal - Swift


If you have a string representation, "ff", you can use UInt8(_:radix:):

let string = "ff"if let value = UInt8(string, radix: 16) {    print(value)}


you can use the function strtoul to convert your hex to decimal:

let result = UInt8(strtoul("ff", nil, 16))  // 255


Try this code, It's work for me.

// Hex to decimal

let h2 = "ff"let d4 = Int(h2, radix: 16)!print(d4) 

Hope this is help for some one