Created
August 13, 2023 12:00
-
-
Save g7uvw/657b1ba23afc3526a1fd2b9af5ec635a to your computer and use it in GitHub Desktop.
Broken int conversion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# data is a number from a sensor - it's either in base 10 or 16. Default is base 10, but it's sometimes 16. | |
# I want to return a decimal value no matter that the input base is. | |
# Thsi is micropython and I get this error | |
# ValueError: invalid syntax for integer with base 16 | |
def uint_le(data,base = 10): | |
val = struct.unpack('<H', data) | |
if (base == 10): | |
return (int(val[0])) | |
if (base == 16): | |
return int('val[0]',base) | |
#if line 10 reads | |
# return int(val[0],base) | |
# I get this error instead | |
# TypeError: can't convert 'int' object to str implicitly |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment