Sorry if this seems really simple, I just can't find it anywhere online.
I have a UInt8 in hex, I need to get it to a decimal. How do I achieve this in swift?
For example:
"ff"
Thanks
If you have a string representation, "ff"
, you can use UInt8(_:radix:)
:
let string = "ff"
if let value = UInt8(string, radix: 16) {
print(value)
}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With