GENERAL: Converting HEX, Binary, etc. File Formats
Information in this article applies to:
- C166 any version
- C251 any version
- C51 any version
- MDK any version
What Options are there for manipulating converting HEX and Binary
file formats? There are older tools that did this, but they do not
run on 64-bit operating systems.
The command line utility srec_cat.exe is an excellent and
more versatile replacement for HEX2BIN, BIN2HEX, BIN2MOT and
This tool is part of the SRecord package version 1.64
hosted on sourceforge.net. SRECORD contains
utilities to read and manipulate Intel HEX files in many ways. From
the summary page of that site:
"The SRecord package is a collection of powerful tools for
manipulating EPROM load files. It reads and writes numerous EPROM
file formats, and can perform many different manipulations."
Other useful features of srec_cat.exe:
Reads Hex files made by Keil OH51, OHX51, OH251 or OH166 or
- Always stores Intel HEX records in ascending order
- Can be invoked from within the Keil IDE
- Runs on Windows OS
Sections in this article:
Please see the following knowledgebase articles how HEX and BINARY
files can be converted, merged and split using the
srec_cat.exe utility together with Keil microcontroller
General HEX File Manipulation
HEX File Manipulation for 8051 Devices
HEX File Manipulation for ARM Devices
General BINARY File Manipulation
Setup the tools to execute srec_cat.exe after each project
- Open µVision
Select the drop down menu Project ->
Options for Target** and click on the User
Below After Build/Rebuild Check the box for
For user command, call srec_cat.exe with
command options. The key
#H can be used for the input hex file
- For Example:
srec_cat.exe #H -Intel -o SortedHexFile.hex -Intel
Note: If many parameters are needed, it is easier
to use a command file. When using a command file for srec_cat.exe in
µVision, be sure to double the '@' character, or µVision might
interpret it as a key
For a full description of all srec_cat.exe parameters, refer to
the SRecord Reference Manual. Here are some
options which are useful with Keil tools:
Suppress the warning message that the HEX records of the input file
are not sorted in ascending address order. OH51, OHX51, OH251 or
OH166 cannot generate HEX files with ascending address order.
-address-length= 2 or 3 or 4
The number of address bytes in the Intel HEX output file (default
is 4: generate extended address records (type 04)
for an address range of up to 4GB). In the command string,
address-length must be before
an output file).
For non-code-banked 8051 applications: avoid generating
extended address records. Set
limit the maximum address space to 64K. Code banked application can
be larger than than 64K.
The length of each HEX record (default is 32:
lines contain up to 32 bytes of data).
For C51, C251, C166 applications: set
-OutputBlockSize=16 (compatible with OH51,
OHX51, OH251 or OH166).
-fill FillValue StartAddress EndAddress
Fills unused areas with the specified constant value.
Suggestion: use the value 0xFF - this
corresponds to value of erased flash.
-crop StartAddress EndAddress
Only loads the specified address area from the previous input file.
Combine this option with
Add an address offset to the previous input file. Positive or
negative values are allowed. Combine this option with
Treat the preceding file name as Intel Hex, e.g., [input filename]
-Intel = interpret the input file as an Intel HEX, or
-Intel = generate an output file in
treat the preceding file name is a binary, e.g., [input filename]
-Binary = interpret the input file as a binary, or
-Binary = generate an output file in
A command file can contain some or all invocation parameters for
Tip: Start a line with '#' to comment everything to the
end of that line.
Can be used after an input or output filename to specify that an
input file should be interpreted as a Motorola S-Record file or an
output file should be generated as a Motorola S-Record file.
-C-Array filename [-INClude]
Can be used after an output filename to specify that it should be
generated as a C-source file with an optional include file.
SEE ALSO FOR 8051
The following Discussion Forum threads may
provide information related to this topic.
Last Reviewed: Monday, July 23, 2018