1

I have a file with binary data which I need to analyze. The data I am looking for is separated in two-byte long parts.

I tried using file.read(2), but this is very slow for a 1.5 MB file.

file = open('data', 'rb')
data = file.read().hex()

is what I currently use to load the data in a b'' object and convert it to hex data for further processing.

Now I need to read always two bytes from this string, how can I achieve this?

F.e.:

...c429c429c429c429...

should be processed as

c429, c429, c429, c429

Where 'c4' equals 1 bytes.

AndiLeni
  • 481
  • 1
  • 6
  • 16
  • `c4` equals 1 byte doesn't it? – blhsing Sep 23 '20 at 16:52
  • @blhsing yes, this was a typo, sorry. – AndiLeni Sep 23 '20 at 16:53
  • It sounds like you need to regroup the incoming iterable into two-part chunks. [This question](https://stackoverflow.com/questions/1915170/split-a-generator-iterable-every-n-items-in-python-splitevery) has a few different ways of doing that, so you can choose one that matches your style. – ThatComputerGuy Sep 23 '20 at 16:59

0 Answers0