Search code examples
stringswiftuint32

How to convert a String to UInt32 in Swift


let temp: String = "0xffeeffff"

How to convert above String to UInt32, because I need to store it in the bitmap which only accept UInt32


Solution

  • Remove "0x" from your string to convert it to UInt32:

    let temp   = "0xffeeffff"
    let result = UInt32(String(temp.characters.dropFirst(2)), radix: 16)