The difference between HEX file and BIN file formats

In the single-chip development HEX file and BIN files are very common file format programming to popular development environment Keil, for example, were created HEX and BIN files, such as:

1. Create HEX: in Keil magic wand which can by checking [> Output> Creat HEX File] let the project output HEX file.

2, create BIN: Check in Run # 1 [wand> User> After Build / Rebuild] Keil under the label, text box Command input while the corresponding User

 fromelf --bin [email protected]! L  will output the BIN file compiled.

 

Closer to home, briefly describe the difference under HEX (left) and BIN (on the right) file:

1, HEX file

HEX file contains both data and address information, so when programming or download HEX file, generally do not require the user to specify the address.

2, BIN file

BIN file only pure data (codes) information, it does not contain an address, so we need to specify the address programming when programming BIN, generally can be modified in the programming tool.

Let's look at the next part of the code generated Keil HEX and BIN files:

HEX ASCII coded file contents are obtained, the books can be opened directly by the editor, the BIN files can not be directly viewed with the editor, it can be converted to hexadecimal and displayed (as downloading a plug-like notepad ++: plug-in installation ):

Very intuitive BIN file data area can be seen only HEX file.

HEX format Interpretation:

  Each row represents a HEX file record (RECORD), the basic format is as follows

  RECORD MARK colon (:) indicates the start flag

  LOAD RECLEN i.e., the data length of the data length of segment INFO or DATA

  OFFSET address offset specifies an offset address relative to the base

  RECTYP     记录类型  记录类型:“00”数据记录 “01”文件结束记录 '02'扩展段地址记录 '03'起始段地址记录 '04'扩展线性地址记录 '05'开始线性地址记录

  INFO or DATA    数据信息  校验值

 首先要注意的时,1-byte中的byte在HEX文件中因为经过ASCII编码的所以用两个字符表示一个16进制即一个字节,,在BIN文件中则是直接用一个字节表示这两字符,上面的图很直观

下面以HEX文件第一行为例,它的含义主要有,02表示数据段“6000”长度为2,0000表示偏移地址,04表示记录类型为扩展线性地址的记录,6000表示线性地址的基地址并且表示的时[16-31]区域即高位地址,[0-15]区域即低位默认为0。

最后的9A为校验值,用0x100减去起始标志(:)后面所有字符累加对256的模值得到的结果作为校验值:0x100-(0x02+0x00+0x00+0x04+0x60+0x00)%256=9A

 

 其他记录类型类似,可以参考PDF:HEX文件详解

 

Guess you like

Origin blog.csdn.net/fancyop/article/details/92840922