How can I convert a binary file to the text declaring a C/C++ array with that content?

On Debian and other Linux distros is installed by default (along with vim) the xxd tool, which, given the -i option, can do what you want:

matteo@teodeb:~/Desktop$ echo Hello World\! > temp
matteo@teodeb:~/Desktop$ xxd -i temp 
unsigned char temp[] = {
  0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x21,
  0x0a
};
unsigned int temp_len = 13;

Leave a Comment