let temp: String = "0xffeeffff"
How to convert above String to UInt32, because I need to store it in the bitmap which only accept UInt32
let temp: String = "0xffeeffff"
How to convert above String to UInt32, because I need to store it in the bitmap which only accept UInt32
Remove "0x" from your string to convert it to UInt32:
let temp = "0xffeeffff"
let result = UInt32(String(temp.characters.dropFirst(2)), radix: 16)
hope this is help you...
extension String {
func toUInt() -> UInt? {
if contains(self, "-") {
return nil
}
return self.withCString { cptr -> UInt? in
var endPtr : UnsafeMutablePointer<Int8> = nil
errno = 0
let result = strtoul(cptr, &endPtr, 10)
if errno != 0 || endPtr.memory != 0 {
return nil
} else {
return result
}
}
}
}