Skip navigation
height_250.gif

Bin2C—Binary to C Converter

Bin2C is a command-line utility for Windows which takes a binary (or HTML or text) file as input and converts it to a C-array that can be directly included in target application code.

Bin2C does not require additional software to be installed (runs stand-alone). Typical usage applications are data that need to be included in a C-program, 
such as FPGA configuration data, bitmaps in portable format (such as GIF, PNG), web pages that need to be delivered by a built-in web server etc.

Resources

Using Bin2C

The Bin2C utility is very simple to use. It expects a path to an existing file as an input parameter as well as a path to an output file. The input file will be read as binary input data and output into a C-array in the output file. The C-array can be easily compiled into an application.

If the utility is started without any file input, it will print its usage information.

Example, Create C-File From Test.html

The following command-line is used: Bin2C.exe test.html test

This results in the following files

  • test.html
  • test.c
  • test.h

 

Content of test.html

<html>
  <head>
    <title>Testpage</title>
  </head>
  <body>
    <p>This is a test paragraph</p>
    <ol>
      <li>This is a test list entry 0</li>
      <li>This is a test list entry 1</li>
    </ol>
  </body>
</html>

 

Content of test.c

/*********************************************************************
*               SEGGER MICROCONTROLLER GmbH & Co. KG                 *
*       Solutions for real time microcontroller applications         *
**********************************************************************
*                                                                    *
*       (c) 2002 - 2015  SEGGER Microcontroller GmbH & Co. KG        *
*                                                                    *
*       www.segger.com     Support: support@segger.com               *
*                                                                    *
**********************************************************************

----------------------------------------------------------------------
File    : test.c
Purpose : Automatically created from test.html using Bin2C.exe
--------  END-OF-HEADER  ---------------------------------------------
*/

#include "test.h"
const unsigned char test_file[198] =
{
  0x3c,  0x68,  0x74,  0x6d,  0x6c,  0x3e,  0x0d,  0x0a,  0x3c,  0x68,
  0x65,  0x61,  0x64,  0x3e,  0x3c,  0x2f,  0x68,  0x65,  0x61,  0x64,
  0x3e,  0x0d,  0x0a,  0x3c,  0x74,  0x69,  0x74,  0x6c,  0x65,  0x3e,
  0x54,  0x65,  0x73,  0x74,  0x70,  0x61,  0x67,  0x65,  0x3c,  0x2f,
  0x74,  0x69,  0x74,  0x6c,  0x65,  0x3e,  0x0d,  0x0a,  0x3c,  0x62,
  0x6f,  0x64,  0x79,  0x3e,  0x0d,  0x0a,  0x3c,  0x70,  0x3e,  0x54,
  0x68,  0x69,  0x73,  0x20,  0x69,  0x73,  0x20,  0x61,  0x20,  0x74,
  0x65,  0x73,  0x74,  0x20,  0x70,  0x61,  0x72,  0x61,  0x67,  0x72,
  0x61,  0x70,  0x68,  0x3c,  0x2f,  0x70,  0x3e,  0x0d,  0x0a,  0x3c,
  0x6f,  0x6c,  0x3e,  0x0d,  0x0a,  0x20,  0x20,  0x3c,  0x6c,  0x69,
  0x3e,  0x54,  0x68,  0x69,  0x73,  0x20,  0x69,  0x73,  0x20,  0x61,
  0x20,  0x74,  0x65,  0x73,  0x74,  0x20,  0x6c,  0x69,  0x73,  0x74,
  0x20,  0x65,  0x6e,  0x74,  0x72,  0x79,  0x20,  0x30,  0x3c,  0x2f,
  0x6c,  0x69,  0x3e,  0x0d,  0x0a,  0x20,  0x20,  0x3c,  0x6c,  0x69,
  0x3e,  0x54,  0x68,  0x69,  0x73,  0x20,  0x69,  0x73,  0x20,  0x61,
  0x20,  0x74,  0x65,  0x73,  0x74,  0x20,  0x6c,  0x69,  0x73,  0x74,
  0x20,  0x65,  0x6e,  0x74,  0x72,  0x79,  0x20,  0x31,  0x3c,  0x2f,
  0x6c,  0x69,  0x3e,  0x0d,  0x0a,  0x3c,  0x2f,  0x6f,  0x6c,  0x3e,
  0x0d,  0x0a,  0x3c,  0x2f,  0x62,  0x6f,  0x64,  0x79,  0x3e,  0x0d,
  0x0a,  0x3c,  0x2f,  0x68,  0x74,  0x6d,  0x6c,  0x3e, };

/****** End Of File *************************************************/

 

Content of test.h

/*********************************************************************
*               SEGGER MICROCONTROLLER GmbH & Co. KG                 *
*       Solutions for real time microcontroller applications         *
**********************************************************************
*                                                                    *
*       (c) 2002 - 2015  SEGGER Microcontroller GmbH & Co. KG        *
*                                                                    *
*       www.segger.com     Support: support@segger.com               *
*                                                                    *
**********************************************************************
----------------------------------------------------------------------
File    : test.h
Purpose : Automatically created from test.html using Bin2C.exe
--------  END-OF-HEADER  ---------------------------------------------
*/
#ifndef __TEST_H__
#define __TEST_H__

#define TEST_SIZE 198

extern const unsigned char test_file[198];

#endif

//__TEST_H__

/****** End Of File *************************************************/

Resources