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:



Push the Input button to select one or multiple binary input files. Push the Output button to select a single C output file. Each file will be encoded as an array of unsigned char.


Example:

unsigned char 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 pngnow[] = {

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

       ...

       0x60, 0x82} ;


Checkboxes:

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


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 *) ;


If "Decode .WAV file" is checked, a wave file is decoded, instead of generating a text image of the binary content. The signed short array holds just the PCM data.

Example:

signed short in[] = {

           86,    229,    164,     -4,     21,      8,   -183,    127,     68,    185,    266,     46,

           ...

           77,    -67,     -2,     33} ;


unsigned long in_size = sizeof(in)/sizeof(signed short) ;

unsigned short in_BitsPerSample = 16 ;

unsigned short in_Channels = 1 ;

unsigned long in_SamplesPerSecond = 8000 ;


signed short indtmf[] = {

            0,    216,    596,    626,    133,   -491,   -677,   -318,     28,   -302,  -1288,  -1982,

           ...

          354,  -4669, -17221, -10562} ;


unsigned long indtmf_size = sizeof(indtmf)/sizeof(signed short) ;

unsigned short indtmf_BitsPerSample = 16 ;

unsigned short indtmf_Channels = 1 ;

unsigned long indtmf_SamplesPerSecond = 8000 ;




Created with the Personal Edition of HelpNDoc: Create iPhone web-based documentation