Reprinted from Http://bbs.21ic.com/icview-126904-1-1.html
Hex files and bin files are the 2 file formats that we often encounter. Here's a brief look at the differences between the 2 file formats:
The 1-hex file includes address information, and the bin file format only includes the data itself
When burning or downloading hex files, the user is not required to specify the address, because the hex file contains the information inside the address. and Burn Write Bin
File, the user must specify the address information.
3-bin file format
In the case of binary files, there is no "format" in fact. The file only includes pure binary data.
4-hex file format
Hex files are made up of records (record). In the hex file, each row represents a record. The basic format of the record is:
+---------------------------------------------------------------+
| RECORD | Reclen | LOAD | RECTYPE | INFO or DATA | Chksum |
| MARK ': ' | | OFFSET | | | |
+---------------------------------------------------------------+
| 1-byte | 1-byte | 2-byte | 1-byte | N-byte | 1-byte |
+---------------------------------------------------------------+
Record types include:
' XX ' data rrecord: Used to record, most of the hex file records are data records
'% ' End of file Record: used to identify the end of the document, placed at the end of the file, identifying the ending of the hex file
' Extended ' Linear address record: A record used to identify an extended linear address
' Extended ' Segment address record: Records used to identify extension segment addresses
In the above 2 kinds of records, are used to provide address information. Each time you encounter these 2 records, you can calculate a "base" address based on the record.
For subsequent data records, the address is calculated based on these "base" addresses.
The specific format of the data record:
+---------------------------------------------------------------+
| RECORD | Reclen | LOAD | RECTYPE | INFO or DATA | Chksum |
| MARK ': ' | | OFFSET | ' 00 ' | | |
+---------------------------------------------------------------+
| 1-byte | 1-byte | 2-byte | 1-byte | N-byte | 1-byte |
+---------------------------------------------------------------+
Look at an example:
: 020000040000FA
: 10000400FF00A0E314209FE5001092E5011092E5A3
: 00000001FF
Analysis of the above hex file:
The 1th record has a length of 02,load offset of 0000,rectype to 04, indicating that the record is an extension segment address record. The data is 0000, and the checksum is
FA. From the length and data of this record, we can calculate a base address, this address is 0x0000. The subsequent data records are based on this address.
Address.
The 2nd record has a length of ten, and LOAD offset is 0004,rectype to 00, indicating that the record is a data record.
The data is ff00a0e314209fe5001092e5011092e5, a total of 16 byte. The checksum for this record is A3. At this point the base address is 0x0000, plus offset,
The starting address of the 16BYTE data in this record is 0x0000 + 0x0004 = 0x0004.
The 3rd record has a length of 00,load offset of 0000,type = 01, and the checksum is ff. Indicates that this is an end of FILE RECORD, which identifies
The end of the file.
In the above example, the actual data is only 16 byte:ff00a0e314209fe5001092e5011092e5, with a starting address of 0x4
4-hex file and bin file size are different
The hex file is a binary value expressed in ASCII. For example, a generic 8-bit binary numeric 0x3f, which is represented by ASCII, requires the character ' 3 ' to be represented separately.
and the character ' F ', each character needs a byte, so the hex file needs > twice times the space.
For a bin file, you can see the size of the file to know the actual size of the data included in the file. And for hex files, the files you see
Size is not the actual size of the data. One is because hex files represent data in ASCII, and the hex file itself includes additional information.
To learn more about the hex file format, please Google INTEL hex to find detailed PDF documents.
Different HEX and BIN