I have a small binary image, that needs to be represented in a C program. The representation will be like:
static const char[] = {0x1, 0x2, 0x3, 0x4...};
(so, the bytes will be represented as a series of chars)
How do I convert a binary file into a nice 0x..,0x.. string? Is there a program to do this?
Use the xxd utility:
$ xxd -i binary.bin > binary.c
Will create binary.c with the following content:
unsigned char binary_bin[] = {
0x01, 0x02, 0x03, 0x04, . . .
. . .
};
unsigned int binary_bin_len = 123456;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With