Differences between Hex and binfile formats

Source: Internet
Author: User

Hex files and binfiles are two common file formats. The following describes the differences between the two file formats:

 

An Intel HEX file is an ASCII text file consisting of a line of text that conforms to the intel HEX file format. In the Intel HEX file, each row contains a hex record.
These records consist of hexadecimal encoded numbers corresponding to the machine language code and/or constant data. Intel hex files are generally used to transfer programs that will be stored in ROM or EPROM
And data. Most EPROM programmers or simulators use intel hex files.

1-The Hex file contains the address information, while the binfile format only includes the data itself.
Generally, you do not need to specify an address when writing or downloading a HEX file because the information in the Hex file already contains the address. While burning Bin
You must specify the address information when creating a file.


3-bind File Format
There is no "format" for binary files ". The file only contains pure binary data.


4-HEX file format
Hex files are composed of records. In the Hex file, each row represents a record. The basic record format 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:
'00' data rrecord: used to record data. Most records in the Hex file are data records.
'01' end of file record: used to identify the end of the file, put it at the end of the file, and identify the end Of the Hex file
'04 'Extended Linear address record: records used to identify Extended Linear addresses
'02 'extended segment address record: the record used to identify the extended segment address

The last two types of records are used to provide address information. Each time you encounter these two records, you can calculate a "base" address based on the records.
For subsequent data records, the addresses are calculated based on these "base" addresses.

Data record format:
+ --------------------------------------------------------------- +
| Record | reclen | load | rectype | info or data | chksum |
| Mark': '| offset | '00' |
+ --------------------------------------------------------------- +
| 1-byte | 1-byte | 2-byte | 1-byte | n-byte | 1-byte |
+ --------------------------------------------------------------- +

Let's look at an example:
: 020000040000fa
: 400ff00a0e314209fe5001092e5011092e5a3
: 00000001ff

Analyze the above HEX file:
The length of the 1st records is 02, the load offset is 0000, And the rectype is 04. This indicates that this record is an extended segment address record. Data is 0000, And the checksum is
Fa. From the record length and data, we can calculate a base address, which is 0x0000. The subsequent data records are based on this address.
Address.
The length of the 2nd records is 10 (16), the load offset is 0004, And the rectype is 00. This indicates that the record is a data record.
The data is ff00a0e314209fe5001092e5011092e5, with 16 bytes in total. The checksum of this record is A3. At this time, the base address is 0x0000, plus offset,
The starting address of the 16-byte data in this record is 0x0000 + 0x0004 = 0x0004.
The length of the 3rd records is 00, the load offset is 0000, type = 01, and the checksum is ff. This is an end of file record, which indicates
The end of the file.

In the preceding example, the actual data is only 16 bytes: ff00a0e314209fe5001092e5011092e5, and its starting address is 0x4.

4-The size of the Hex file differs from that of the BIND file.
The Hex file uses ASCII to represent binary values. For example, if the 8-bit binary value 0x3f is used, the characters '3' must be represented respectively in ASCII'
And the character 'F', each character requires a byte, so the Hex file needs to have more than twice the space.
For a binfile, you can view the file size to know the actual size of the data contained in the file. For the Hex file, the file you see
The size is not the actual data size. First, the Hex file uses ASCII to represent data, and second, the Hex file itself contains additional information.
In addition, hex will ignore the blank areas in the middle unless the data is filled; but the bin will be filled completely.
For example, if your single-chip machine is kb and you define a constant byte data to the end, the actual bin size must be kb, and the data not defined in Hex is empty, no production records.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.