Intel Hex

I wrote this document because I found it hard to find any (correct) information about Intel Hex on the net. This document is far from complete, but represents the sum of my knowledge.

Intel Hex consists of a number of printable ASCII lines called records. Each record consists of a colon (:) followed by a number of fields in hex:


Length field. The size of the data field in bytes.
Address field. Address of the first byte of data in the record.
Record type field.
Data field. The size of this field is variable.
Checksum field.

An Intel Hex file consists of a number of type 0 (data) records followed by a type 1 (end of file) record. Type 2 (offset) records are an extension to the standard which allow an offset to the address to be applied.

Type 0 (data) record
This records store data and the address it should be written to. The length of the record is often 16 or 32 bytes.
Type 1 (EOF) record
This record indicates the end of the file. It has a length of 0 and an address of 0. Some older programs expect :0000000000 as the EOF.
Type 2 (offset) record
This record sets an offset to the address of data records. It has a length of 2 and an address of 0. The data field is used as the offset until an end of file or another type 2 record is encountered. The address field covers bits 0-15 of the physical address and the offset bits 4-19 (there is an 12 bit overlap).

The checksum is the bottom eight bits of the 2's compliment of the sum of the the bytes in the record.