Aug-11-2021, 02:46 PM
(Aug-11-2021, 02:06 PM)DeaD_EyE Wrote: The provided example could not work because the quoting is missing.
import binascii from_your_post = "d8 59 80 a2 c8 be f4 92".replace(" ","") # unhexlify can not handle whitespaces, so I've replaced them with nothing raw_bytes = binascii.unhexlify(from_your_post) # iterating over bytes -> you get integers (0-255, one Byte) back # accessing an index on raw bytes also return an int # consuming raw_bytes with a list, tuple or other sequence types, will also make integers # but accessing a range of bytes, will still return raw bytes # the bytes type in Python is a hybrid. for value in raw_bytes: print(value, type(value))To keep the values, you can append them to a list or consume the raw_bytes with a list:
integers = list(raw_bytes) print(integers)
Output:[216, 89, 128, 162, 200, 190, 244, 146]
I did somthing else , and now I have the wanted value were I want it
but when I try to convert it from Hex str to int I get error?
['ee', 'ad', 'd0', '76', 'dd', 'ff', '52', '00'] <class 'str'> Traceback (most recent call last): File "Documents/GetVIN.py", line 61, in <module> x = int(TestValue, 16) ValueError: invalid literal for int() with base 16: "['dd']" "this is what I have done:
def CutData(FullData, StartByte, length=1): StartByte = StartByte - 1 EndByte = StartByte + length Data_Byte = FullData.split(' ') print(Data_Byte) Wanted_Data = str(Data_Byte[StartByte:EndByte]) print(type(Wanted_Data)) return Wanted_Data TestValue = (CutData(Data, 5, 1)) x = int(TestValue, 16) print(x)what is wrong?
I have str in hex and want to make it an int
is the command is wrong?
what am I missing?
Thanks,