I gradually master Python and write a program for communicating with the AVR controller via bluetooth.
From the socket, I receive data as a string of bytes of this type b'\xb1\xaa\xab\xac\xad\xae\xaf' .
Since I am writing my own protocol and working with different data types (I send them from MK not in symbolic form), I break the line into parts, for example: b'\xb1' , b\xaa\xab' and b\xac\xad\xae\xaf' , that is, a one-byte int, a two-byte int, and a four-byte int, with which there are no problems.
The main task is to convert these byte sequences into original numbers. One-byte int quite turns out to transform as:
In [64]: line = b'\t\xaa\xab\xac\xad\xae\xaf' In [65]: line [0] Out[65]: 9 In [72]: a = line [0] In [73]: a Out[73]: 9 In [74]: a += 1 In [75]: a Out[75]: 10 But here the method of converting to the number of two or more buy is unknown to me As a result of the search more confused. And so, the question is: how do you have byte strings of the form b\xaa\xab' and b\xac\xad\xae\xaf' in the source data to bring them to an integer data type?