how to convert hex to decimal in swift?
I have string "423fdf4dfb1115" and I need get this => 18647576781459733.
I try this:
let result = UInt8(strtoul("423fdf4dfb1115", nil, 16))
but app crash...
I use this online convert: http://www.binaryhexconverter.com/hex-to-decimal-converter
The result must be UInt64
(UInt8.max
is 255).
There is a convenience initializer, strtoul
is not needed.
let string = "423fdf4dfb1115"
let result = UInt64(string, radix:16)
let result = UInt64(strtoul("423fdf4dfb1115", nil, 16))
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