The microcontroller used file formats HEX and BIN distinctionHEX and BIN

Microcontroller learning, we often come into contact with the hex file and bin file, then what exactly between raising the difference between them?
HEX file and BIN files that we often encounter two kinds of file formats. Following is a brief look at the difference between these two kinds of file formats:
1, HEX file including address information, and BIN file formats include only the data itself. Programming or download the HEX file, and generally do not require the user to specify the address, including the address because the HEX file inside information. Program the BIN file, the user is necessary to specify the address information.
2, BIN file format
In fact, there is no "format" of the binaries. The file only includes pure binary data.

3, HEX file format
HEX file record (RECORD). HEX file inside, 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:
'00 'Data Rrecord: Most of the records are used to record the data, HEX file data record
'01 'End of File Record: used to identify the file to the end, on the document's final, marking the end of the HEX file
'04 'Extended Linear Address Record: extended linear address record is used to identify
'02 'Extended Segment Address Record: used to identify the extended segment address record
In the latter of the above two kinds of recording, are used to provide the address information. Each encounter two records can be calculated according to records of a "base" address. For the back of data recording, when the address is calculated, are these "group" address basis.
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
HEX file above analysis:
A record length of 02 LOAD the OFFSET to 0000, the RECTYPE 04, the record for the extended segment address record. The data for 0000, checksum FA. Length and data from this record, we can calculate a base address, the address is 0X0000. Subsequent data record at this address as a base address.
2 length of the record 10 (16) Load the OFFSET 0004 the rectype 00, the description of the recording for the data record. The data FF00A0E314209FE5001092E5011092E5, a total of 16 BYTE. Record check and A3. In this case, the base address is 0X0000, coupled with the OFFSET, record 16BYTE data starting address is 0x0000 + 0x0004 = 0x0004. 3 record length of 00 LOAD the OFFSET 0000 TYPE = 01, parity and FF. This is the end of an END OF FILE RECORD identification documents.
In the above example, the actual data is only 16 BYTE: FF00A0E314209FE5001092E5011092E5 its start address to 0x4

4, HEX file and BIN file size
HEX file using ASCII to represent binary values. Such as general 8-BIT binary value 0x3F ASCII on the need to represent the character '3 'character' F ', each character requires a BYTE, HEX file needs> 2 times the space. A BIN file, you look at the size of the file you can know the actual size of the data file included. HEX file, you see the file size is not the size of the actual data. HEX file to represent data using ASCII HEX file also includes other additional information.

One example to illustrate:
Table 1
ORG 0000H
LJMP START
ORG 040H
START:
MOV SP, # 5FH; located Stack
LOOP:
NOP
LJMP LOOP; circulation
END; End
Table 2
: 03000000020040BB
: 0700400075815F000200431F
Table 3
02 00 40 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
FF FF FF FF FF FF FF FF FF FF FF FF 75 81 5F 00 02 00 43
Table 1 source, Table 2 HEX file after compilation, Table 3 is converted by the HEX file into the target file, that is ultimately written to the EPROM file by Programmer conversion, can also by HEXBIN a class the program conversion. Learned manual compilation should not be hard to find out the one-to-one correspondence between Table 3 and Table 1, it is noteworthy from 020,040 after a long string of 'FF' until 7581, which is due to the directive: ORG 040H result.