Hex2bin 1.0.12

This tool is used for converting hexadecimal files (either Motorola or Intel format) into a binary file. It's a command line tool with basic capabilities.

Hex2bin/mot2bin Features

It can handle the extended Intel hex format in segmented and linear address modes. Records need not be sorted and there can be gaps between records.  Holes/unused bytes can be specified as any other value than FF. A checksum can be inserted into the binary file.

The source files can be easily compiled for Windows, either by using CodeBlocks + MinGW GCC or Microsoft Visual Studio (or Express). For convenience, the distributed file contains the 64-bit executables for Windows already.


Hex2bin and mot2bin are released with a BSD license.


Checksum of source file

By default, it ignores checksum errors, so that someone can change by hand some bytes allowing quick and dirty changes.

If you want checksum error reporting, specify the option -c.

hex2bin -c example.hex

If there is a checksum error somewhere, the program will continue the conversion anyway. For convenience,

hex2bin/mot2bin displays the expected checksum at each faulty records.

Extension for output file

By default, the extension will be .bin. Another value can be specified.

hex2bin -e com example.hex

A file example.com will be generated.

Padding byte

By default, unused locations will be filled with FF. Another value can be specified.

hex2bin -p AA example.hex

Starting Address and Length

If the lowest address isn't 0000, ex: 0100: (the first record begins with :nn010000xxx ) there will be problems when using the binary file to program a EPROM since the first byte supposed to be at 0100 is stored in the binary file at 0000.

you can specify a starting address on the command line:

hex2bin -s 0000 start_at_0100.hex

This start address is not the same thing as the start address record in the hex file. The start address record is used to specify the starting address for execution of the binary code.

The bytes will be stored in the binary file with a padding from 0000 to the lowest address minus 1 (00FF in this case).

Similarly, the binary file can be padded up to Length -1 with FF or another byte.

Here, the space between the last byte and 07FF will be filled with FF.

hex2bin -l 0800 ends_before_07FF.hex

EPROM, EEPROM and Flash memories contain all FF when erased.

When the source file name is for-example.test.hex the binary created will have the name for-example.bin

the ".test" part will be dropped.

Hex2bin/mot2bin assume the source file doesn't contain overlapping records, if so, overlaps will be reported.

Minimum Block Size

The output file size will be a multiple of Minimum block size. It will be filled with FF or the specified pattern.

Length must be a power of 2 in hexadecimal [see -l option].

Attention this option is STRONGER than Maximal Length.

hex2bin -m [size] example.hex

Checksum inserted inside binary file

A checksum value can be inserted in the resulting binary file.

hex2bin -k [0|1|2] -r [start] [end] -f [address] [value]

-k Select checksum type:

0 = 8-bit checksum

1 = 16-bit checksum, little endian

2 = 16-bit checskum, big endian

-r Range to compute checksum over (default is min and max addresses)

-f Address and value of checksum to force

Support for byte-swapped hex/S19 files

Some compilers such as Microchip's MPLAB IDE can generate byte swapped hex files.

hex2bin -w test-byte-swap.hex

-w Wordwise swap: for each pair of bytes, exchange the low and high part.

If a checksum needs to be generated to insert in the binary file, select one of the 16-bit checksums.


Hex2bin and mot2bin are in production status. It is working well for many small applications.

While I'm now working on other projects, hex2bin and mot2bin are still open for patches, feature request etc. Submit them here.

SRecord has many more features and support many other formats.


The source file contains a version compiled for 64-bit windows.

Download Hex2bin

Valid HTML 4.01 Transitional

CSS Valide !

SourceForge Logo