I have a binary file that has some fields encoded as BCD (Binary Coded Decimal). Example as below.
14 75 26 58 87 7F (Raw bytes in hex format).
I am using (np.void, 6) to read and convert from binary file and below is the output I am getting.
b'\x14\x75\x26\x58\x87\x7F'
But I would like to get the output as '14752658877', without the fill character 'F' using numpy.
Below is the code: with open (filename, "rb") as f:
while True:
chunk = f.read(chunksize)
if (chunk):
dt = np.dtype([('a','b'), ('b', '>i4'), ('c', 'S15'),('d', np.str, 7),
('e', 'S7'), ('f', np.void, 6)])
x = np.frombuffer (chunk, dtype=dt)
print (x)
else:
break
Also, the input file contains many fixed length binary records. What is the efficient way to convert and store it as ascii file using numpy.