How to convert hexadecimal to decimal in Swift

1 Answer

0 votes
import Foundation

let hex = "1D7F"

if let dec = Int(hex, radix: 16) {
    print(dec)
} else {
    print("Invalid hex number")
}



/*
run:

7551

*/

 



answered Feb 14, 2025 by avibootz
...