I try to create a small iOS app in Xcode, using Swift 3. I try to connect to a BLE device and then read battery level.
I get this response:
...UUID = Battery Level, properties = 0x12, value = <30>...
And then I try to convert the HEX 30 to decimal 48. But I don't know how.
I have tried this:
print(String(bytes: characteristic.value!, encoding: String.Encoding.utf8))
print(Int(strtoul(str, nil, 16)))
let dataBLE = String(data: characteristic.value!, encoding: String.Encoding(rawValue: String.Encoding.utf8.rawValue))
print(dataBLE)
But none of these work. How can I convert from hex to decimal with the value from characteristic.value
?