I am using python as the main scripting language on a micro controller. The micro controller reads two 8-bit hex numbers from the I2C bus; for example:
out_L = C2
out_H = F2
Both these are received as strings in python. F2C2 represents a two's complement number. I need the decimal value of the number.
I can convert the hex strings to binary strings with
bin_out = "0b" + ( bin(int(hex_out, 16))[2:] ).zfill(8)
Now I have to convert the binary value to a decimal value which is where I am stuck. I first have to do two's complement convertion and then convert to decimal. Because the binary value is still a string I can't do normal binary operations on it and can't convert it to decimal. Please assist. All my efforts to correctly change the binary string to binary value provides me with the incorrect value.