BIN to C / H
Convert binary file to C-Array header (.c / .h) for Arduino & ESP32 — 100% private client-side processing.
Active Converter
BIN to C / H Array: Embedding Binary Assets in Arduino, ESP32 & STM32
Technical Anatomy of C Byte-Array Headers
Bare-metal microcontrollers and lightweight RTOS targets frequently lack an SD card slot or filesystem partition like LittleFS or SPIFFS. When your firmware needs to render a company logo on an SPI TFT display, play a startup beep over a DAC, or serve a compressed index.html.gz configuration portal, the cleanest solution is compiling the binary payload directly into the firmware executable as a C/C++ header (.h) or source file (.c).
Converting a binary file into a C array iterates over every byte in the input stream, formats each octet as a zero-padded hexadecimal literal (0x00–0xFF), wraps lines at 12 or 16 elements for readability in Git diffs, and appends an explicit unsigned int length constant. Declaring the array const unsigned char (or const uint8_t from <stdint.h>) signals the GCC or Clang linker to place the payload inside read-only flash memory rather than scarce RAM.
Raw Binary Input vs. Generated C/H Header Output
// Input: 12-byte monochrome OLED icon (icon_wifi.bin)
// Raw bytes: 00 3C 42 99 A5 81 42 3C 18 18 00 00
// Generated C Header Output (icon_wifi.h):
#include <stdint.h>
const unsigned char icon_wifi_bin[] = {
0x00, 0x3C, 0x42, 0x99, 0xA5, 0x81, 0x42, 0x3C,
0x18, 0x18, 0x00, 0x00
};
const unsigned int icon_wifi_bin_len = 12;
Real-World Software & Hardware Ecosystem
Embedded engineers rely on C byte arrays across PlatformIO, Arduino IDE, ESP-IDF, STM32CubeIDE, Zephyr RTOS, and Raspberry Pi Pico SDK. Typical production use cases include embedding LVGL UI sprites, Adafruit_GFX display bitmaps, TensorFlow Lite for Microcontrollers quantized .tflite neural network models, and static web assets for captive portals on ESP8266/ESP32 Wi-Fi modules.
Troubleshooting & Edge Cases
- Duplicate Symbol Linker Errors: If you include the generated
.hfile in two different.cppfiles withoutstatic constor header guards (#pragma once), the linker will throw amultiple definitionerror. Place the array in a single.cfile and expose it withextern const unsigned char[]. - Flash Partition Overflow: Always check your board's flash map before embedding multi-megabyte assets. On ESP32, switch to a
Huge APP (3MB No OTA)partition scheme if large binary arrays push your sketch past the default 1.2 MB app limit. - Alignment Requirements for DMA Transfers: STM32 and ESP32 SPI/I2S DMA peripherals often require 4-byte aligned buffers. Add
__attribute__((aligned(4)))to the generated array declaration when feeding it directly to hardware DMA.
Microcontroller Flash Placement Directives by Architecture
| MCU Family | Recommended Declaration | Memory Placement |
|---|---|---|
| AVR (Arduino Uno/Mega) | const uint8_t data[] PROGMEM = {...}; | Flash (read via pgm_read_byte) |
| ESP32 / ESP8266 | static const uint8_t data[] = {...}; | Auto-mapped to Flash .rodata |
| STM32 / RP2040 (ARM) | const uint8_t data[] __attribute__((aligned(4))) | Flash .rodata, DMA-aligned |
Unix xxd -i Equivalent Command
# Generate the exact same C header array in Linux/macOS:
xxd -i icon_wifi.bin > icon_wifi.h
Frequently Asked Questions
AVR microcontrollers like the ATmega328P have only 2 KB of SRAM but 32 KB of Flash program memory. Without PROGMEM, a large const unsigned char[] bitmap or audio buffer is copied into SRAM at boot, immediately crashing the sketch with stack corruption.
On ESP32 and ARM Cortex-M (STM32, RP2040), declaring an array as static const uint8_t automatically places it in read-only Flash (.rodata) without needing pgm_read_byte(). The PROGMEM macro is kept as a harmless compatibility no-op in ESP32 Arduino cores.
It produces the exact same C-compatible hexadecimal byte initializer list (0x00, 0xFF, ...) plus a matching length constant, allowing embedded developers on Windows, macOS, or Chromebooks to generate .h header files directly without installing Unix toolchains.
Monochrome OLED/e-Paper bitmaps (SSD1306, ST7789), custom TrueType/BDF fonts, short PCM/WAV chime clips, TLS root CA certificates, and gzipped HTML/JS dashboards served from an ESP32 AsyncWebServer.