I have a file with text and binary. Text is used to identify beginning and end of a chunk of binary data, which represents a list of complex numbers, e.g. (1.5+5.6j)(...).
I have implemented the following to detect where the data starts and ends but I am not sure how to parse the data to extract the complex numbers.
Input file 'short.log':
NOW: ^@ºÿ¦ÿÉ^B<80>^AÓ^@k^C^HüÀ^Búú<88>^@^Uü4ÿ^[ÿ<88>^@»^@}^A^@N^Auÿi^Bòü5^E¿ùï^DHûÍÿö^CÈü^C^KÌ^@¡^H^D^GÿþP^E¡ö]ý<95>öñ÷Ùûøú^@j^@ END
And this is the code to read it:
from bitstring import ConstBitStream
import os
import struct
bin_file = 'short.log'
byte_data = b'NOW: '
def parse(byte_data):
fileSizeBytes = os.path.getsize(bin_file)
data = open(bin_file, 'rb')
s = ConstBitStream(filename=bin_file)
occurances = s.findall(byte_data, bytealigned=True)
occurances = list(occurances)
totalOccurances = len(occurances)
byteOffset = 0
occurances2 = s.findall(b' END', bytealigned=True)
occurances2 = list(occurances2)
totalOccurances2 = len(occurances2)
byteOffset = 0
for i in range(0, len(occurances)):
occuranceOffset = (hex(int(occurances[i]/8)))
s.bitpos = occurances[i]
data = s.readto(b' END')
parsedata(data)
def parsedata(data):
#Here to parse complex number
parse(byte_data)