IntelHexToBin Convertor
It is a simple command line tool and can be used to convert hex files into binary files.
Hex File
Intel hex file is an encoded binary file, coded in ASCII text format. This file format is widely used for programming all kinds of processors. Programs written in assembly, C, C++ etc are converted into corresponding .hex files by the compilers, which are then imported by a program to decode and burn the binary code into microcontroller’s ROM.
Intel HEX consists of lines of ASCII alphanumeric characters. Each line starts with a character ‘:’. The lines are termed as a record. Each record contains blocks of hexadecimal characters that encode record type, length, memory load address, and checksum.
RECORD MARK: Field contains the ASCII code for the colon (’ : ’) character.RECLEN: Field specifies the number of bytes of data. The maximum value of the RECLEN field is 255.
LOAD OFFSET: Field specifies the 16-bit starting load offset of the data bytes, therefore this field is only used for Data Records. In other records where this field is not used, it should be coded as four ASCII zero characters (’0000’ or 03030303OH).
RECTYP:: Field specifies the record type of this record. The RECTYP field is used to interpret the remaining information within the record. The encoding for all the current record types are:
’00’ Data Record
’01’ End of File Record
’02’ Extended Segment Address Record
’03’ Start Segment Address Record
’04’ Extended Linear Address Record
’05’ Start Linear Address Record
CHKSUM: Field contains the ASCII hexadecimal, which is the sum of all the ASCII pairs in a record after converting to binary, form the RECLEN field to and including the CHKSUM field, is zero.
Bin File
A binary file with a name extension of ".bin" is a file which contains the machine language code, stored in binary format. Processors understand only the code in the binary files not the hex files. So hex file is first converted into binary and then flashed into the microcontroller ROM. File contains sequence of bytes, which means the binary digits (bits) that are grouped in eights. which means the binary digits (bits) that are grouped in eights.
How to use the Tool?
The source code of the tool is written in Java. Two classes are defined, one reads the hex file and writes the converted binary data into the binary file. And other one processes and parses the hex file to get the binary data.
The project is exported as a .jar file which is then executed through command line.
IntelHexToBin [option] .hex [option] .bin [option] 0xYYYY [option] 0xZZZZ.
All the options are case sensitive.
-- help,IntelHexToBin -h
-h prints usage of the tool.IntelHexToBin –i iiii.hex –o oooo.hex
--input-i valid filename / path, If the file iiii.hex doesn't exist, the program throws an error “File access failed!!!!!provide a vaild input/output path”.
--output
-o valid filename with path, If the file oooo.hex doesn't exist, the program creates a new file to write the bin data.
If you want to decode hex file for a specified memory range, then you must provide the start and end address.
IntelHexToBin –i iiii.hex –o oooo.hex –s 0xYYYY -e 0xZZZZ
--start address-s valid hexadecimal number
--end address
-e valid hexadecimal number