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
  • 457
  • 1
  • 4
  • 16

1 Answers1

0

It sounds like you need to regroup the incoming iterable into two-part chunks. This question has a few different ways of doing that, so you can choose one that matches your style.