Turn any file into a C or C++ byte array you can compile straight into firmware or an application, just like xxd -i. Choose hex or decimal, the bytes per line, the element type, and add const, static, PROGMEM, alignment or a header guard.
Last updated:
Offset and count accept decimal or 0x hex.
Advertisement
Advertisement
How to use the File to C Array
Drop a file (or switch to the Text tab and type a string).
Check the variable name; it is made from the file name, with dots, dashes and spaces turned into underscores.
Pick the format: element type, hex or decimal values and bytes per line.
Add qualifiers such as const, static or PROGMEM, and choose how the length is exported.
Copy the code or download the .h file and include it in your project.
Example output
For a 23-byte text file named hello.txt, the default settings produce (untick const to get exactly what xxd -i prints):
Use it like any other array: fwrite(hello_txt, 1, hello_txt_len, f); or, for a PROGMEM array on AVR, pgm_read_byte(&hello_txt[i]).
Options compared
Option
What it adds
When to use it
const
const unsigned char name[]
Almost always: read-only data can stay in flash or a read-only section.
static
static linkage
When the header is included in several .c files, to avoid duplicate symbol errors.
PROGMEM
PROGMEM + #include <avr/pgmspace.h>
AVR boards (Uno, Nano, Mega) to keep data out of SRAM.
Align to 4 bytes
__attribute__((aligned(4))) or alignas(4)
DMA buffers, or reading the bytes as 32-bit words.
Header guard
#ifndef NAME_H … #endif
When the file is saved and included as a .h header.
0x00 terminator
One extra zero byte
Embedding text that will be used as a C string.
C++ std::array
constexpr std::array<T, N>
Modern C++ code that wants the size in the type and compile-time access.
Alternatives to a byte array
C23 #embed: newer compilers (GCC 15, Clang 19) support #embed "file.bin" inside an initializer, which reads the file at compile time.
Linker objects: ld -r -b binary file.bin -o file.o or objcopy turn a file into an object with _binary_file_bin_start and _end symbols.
Byte arrays (this tool) remain the most portable choice: they work with every compiler, IDE and microcontroller toolchain and need no build-system changes.
Frequently asked questions
Is the output the same as xxd -i?
Yes, apart from a one-line comment naming the file. Untick const and keep the other defaults (C array, unsigned char, lowercase hex, 12 bytes per line, unsigned int length) and the layout matches xxd -i: an unsigned char array named after the file, two-space indentation, and an unsigned int name_len variable holding the byte count.
How is the variable name made from the file name?
Every character that is not a letter, digit or underscore becomes an underscore, so logo.png becomes logo_png and font-16px.bin becomes font_16px_bin. A name that would start with a digit gets a data_ prefix, because C identifiers cannot begin with a number. You can type any other name.
What does PROGMEM do?
On AVR microcontrollers such as the Arduino Uno, const data is still copied into the small SRAM at startup. Adding PROGMEM (from avr/pgmspace.h) keeps the array in flash memory instead, and you read it with pgm_read_byte(). On ESP32, ARM and most other chips, const alone already keeps data in flash.
Should I use unsigned char or char?
Use unsigned char or uint8_t for binary data. Plain char is signed on most compilers, so values above 0x7F do not fit, which is a narrowing error in C++ brace initialisation and a warning in C. If you choose char or signed char, those bytes are written with an explicit cast.
Why add a 0x00 terminator?
Appending a zero byte lets you use an embedded text file (HTML, JSON, a shader or a certificate) directly as a C string. The length value then includes that extra byte.
How large a file can I convert?
Files up to 32 MB can be converted in the browser. The text output is roughly six times the file size, so very large outputs are only previewed partly on screen, but copying and downloading always give the full header.
Is my file uploaded?
No. The file is read with the browser's File API and the header is generated on your device.
Are all the tools on FreeToolCabin tested for quality and accuracy?
Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.