ARM Technical Support Knowledge Articles

CREATING C FILES FROM BINARY OR HEX DATA

Applies to: General Topics

Answer


Information in this article applies to:


QUESTION

I have some binary data that I want to convert to a C array to use in my application. What's the best way to do this?

ANSWER

A product called the HEX Workshop is available from www.bpsoft.com. They offer an evaluation version that you may download from their web site.

To create a C array from binary or even HEX data...

  1. Open the binary data file or Import the existing HEX file.
  2. Export the file as C source. The resulting file will be a C file that appears similar to the following:
    // Generated by BreakPoint Software's Hex Workshop v3.11
    //   http://www.hexworkshop.com
    //
    // Source: C:TEMPlj0	est.hex.bin
    //   Time: 2/8/2002 1:04 PM
    // Offset: 0 / 0x00000000
    // Length: 84 / 0x00000054
    
    
    unsigned char rawData[84] = {
        0x02, 0x00, 0x41, 0x8E, 0x08, 0x8F, 0x09, 0x85, 0x09, 0x82, 0x85, 0x08, 0x83, 0xE0, 0xFE, 0xA3,
        0xE0, 0x8E, 0x0A, 0xF5, 0x0B, 0x4E, 0x70, 0xEF, 0x85, 0x09, 0x82, 0x85, 0x08, 0x83, 0xE0, 0xFE,
        0xA3, 0xE0, 0xFF, 0x7C, 0x00, 0x7D, 0x00, 0x02, 0x00, 0x00, 0x7B, 0x00, 0x7A, 0x00, 0x79, 0x01,
        0x80, 0x06, 0x7B, 0x00, 0x7A, 0x00, 0x79, 0x00, 0x8A, 0x0A, 0x89, 0x0B, 0xE9, 0x4A, 0x70, 0xD8,
        0x22, 0x78, 0x7F, 0xE4, 0xF6, 0xD8, 0xFD, 0x75, 0x81, 0x0B, 0x02, 0x00, 0x4D, 0x7F, 0x00, 0x7E,
        0x80, 0x02, 0x00, 0x03,
        } ;
    
  3. You may rename the array rawData to whatever name you like.

Article last edited on: 2005-07-09 12:45:41

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential