In python, assume that there is data when I run…
search = target.readframes(2205)
Each frame consist of 2 bytes. I want to compare each 2-byte value and extract highest 2 values in the range.
For example, if the data looks like this…
0000|0001|0002|0008|0007|000F|000D|000A|00FB|00FC|00FA|00F9|00F8|00D7|00C3|0000
Then the result would extract 000F and 00FC
Could someone please help me achieve this. Any answers or helpful advise would be great.
First, you should use only
bytesobjects if you deal with binary data. They require Python 2.6+.Example
And yes, you can use normal compare operations with bytes.
I am not sure that kind of object is returned by your
readframesbut if it is not bytes by design you should convert it to bytes. You can just usedata = bytes(obj).Do not use strings to process binary data.