Operation

Operation ››
Parent Previous Next

Generating C Source Code


Bin2C is a utility to generate C source code from binary files. Its use is simple and straightforward. When starting Bin2C, the following dialog appears (but the fieds will be empty on a fresh installation):



Push the Input button to select one or multiple binary input files. Note that the file names are used to build the variable names, so make sure to use file names which conform to the C variable naming convention. Push the Output button to select a single C output file. Each input file will be encoded as an array of the data type specified in the "Data type" dialog item.


Example:

unsigned char CONST_MEM pngbar[] = {

       0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52,

       ...

       0xd9, 0x51, 0xee, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82} ;


unsigned char CONST_MEM pngnow[] = {

       0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52,

       ...

       0x60, 0x82} ;


Checkboxes:


The optional header and footer definitions will lead and trail the generated data. They depend on the employed software tool chain and may be used to place the binary data into a specific segment in the target system.


If "Generate table of contents" is checked, an array of pointers to the individual data arrays is generated.

Example:


unsigned char *toc[] ={

       pngbar,

       pngnow,

       pngout,

       pngtest} ;

int toc_size = sizeof(toc)/sizeof(unsigned char *) ;


"Add alternative text" is meant as an option for debugging. If it is selected, a conditionally compiled block is inserted into the output file, which just defines strings of filenames rather than the real data. That block is compiled, when EMBEDDEDPNG is not defined. This permits to generate a small test version of the project without any possibly large embedded binary files.


"Add 'extern' declaration" will add a block of external data declarations, which are only used, if DECLARE_VARS is undefined. Otherwise the generated data blocks will be used. This allows to embed the data in just one file and reference it from other files in the project.


If "Sort Input Files" is checked, the input files are sorted by name, before they are written to the output file.


Bin2C will generate some statistics and put them as comments at the start of the output file. It contains a table of contents of the embedded files and lists the line numbers where the individual files start. WAV and PNG files are analyzed and their properties are listed in the table as well.





Created with the Personal Edition of HelpNDoc: Easily create Web Help sites