I am working with Python and the GATT library, pxexpect to handle some data, but I am encountering an issue when trying to convert a hexadecimal value to an integer. Here’s the specific error I’m seeing:
“””
print(int(gatt.before, 16)),
^^^^^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 16: b’0f 18 ‘
“””
This is the code which produces the error..
“””
print(int(gatt.before, 16)),
print(“%”)
“””
The variable gatt.before contains a value b’0f 18 ‘. It appears that this is a bytes object representing a hexadecimal value with spaces. However, int() with base 16 expects a string without spaces.
What I’ve Tried:
Removing Spaces:
I tried stripping the spaces, but that didn't solve the issue.
Decoding:
I used .decode('utf-8') to convert the bytes object to a string, but that didn’t help either.