I have various .hex files. Some of them start from address 0x0000, some from 0x3000. In the second option I have to fill the missing addresses with 'F's. But after simply converting the .bin file to .hex I don't get the knowledge about the first address. Is there a way to know it so that the program could decide whether it is neccessary to add some chars?
Asked
Active
Viewed 683 times
0
-
No, I mean if there is a way to check it in python. I know it when I open .hex file. But how to check it using a program. When I convert .bin file to a readable file I just get raw values. It doesnt give me info about first address or anything – immonual123 Nov 24 '21 at 09:19
-
So, the convertion takes out the black chars only. And that is ok. But I need to check in a program whether the .hex file starts form 000000 or 0030000. I dont even know if that is possible to do, since I dont see any option from few days – immonual123 Nov 24 '21 at 09:50
1 Answers
0
The most simple way of determining the first address in one of these .hex files would be to open it as a text file, read the second line, extract the characters in columns 4–7 and parse them as a hexadecimal number:
with open('example.hex') as f:
first_line = next(f)
second_line = next(f)
first_address_str = second_line[3:7]
first_address = int(first_address_str, 16)
if first_address == 0:
# do something
elif first_address == 0x3000:
# do something else
else:
# do something else
Of course, there are already libraries to make dealing with such files more convenient and reliable, for example: https://pypi.org/project/intelhex/

mkrieger1
- 19,194
- 5
- 54
- 65