You can use regular expression for this, e.g.
import re with open('1.bin', 'rb') as f: s = f.read() for match in s.finditer(b'\xFF\x00'): # UPD: should be re.finditer(b'\xFF\x00', s) print(match.span())