PRIVATE BROWSER TOOL
Convert a binary file to a source-code array
Embed small firmware blobs, certificates, assets or test vectors directly in source code without sending the file to a server.
Inputs
Results
Run the tool to see a structured report here.
ON THIS DEVICE
Recent history
Your latest 10 runs will appear here on this device.
HOW IT WORKS
Method and formulas
Each input byte is emitted as a two-digit hexadecimal literal. The requested identifier is normalized to a valid source-language name.
Always compare generated firmware with the target device’s memory map, linker output and programming documentation before flashing.
GUIDE
What this tool does and when to use it
This converter accepts any binary file and emits its contents as a static byte array declaration suitable for direct inclusion in C, C++, Rust or Python source. Each byte becomes a two-digit hexadecimal literal prefixed with 0x, separated by commas, and wrapped at the chosen line width. The supplied identifier is sanitized to a valid name for the target language by replacing invalid characters with underscores and ensuring it does not begin with a digit. Engineers commonly employ the output when embedding firmware images, font bitmaps, cryptographic keys or calibration tables inside microcontroller projects where a separate resource file is undesirable. Because conversion occurs entirely inside the browser, no data leaves the local machine and no server-side processing occurs.
Worked example with realistic input
Consider a 32-byte binary fragment representing a small boot header: the bytes 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x02 0x00 0x3E 0x00 0x01 0x00 0x00 0x00 0x70 0x04 0x40 0x00 0x00 0x00 0x00 0x00. Selecting C language, identifier elf_header and line width of eight produces the following array. The table below shows the first two output lines for clarity.
| Line | Generated source |
|---|---|
| 1 | const unsigned char elf_header[] = {0x7F,0x45,0x4C,0x46,0x02,0x01,0x01,0x00, |
| 2 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
Subsequent lines continue until all 32 bytes are emitted, terminating with a closing brace and semicolon. Equivalent Rust output uses let ELF_HEADER: [u8;32] while Python uses ELF_HEADER = b'\x7f...'. The normalization step converts an input name such as "my-header.bin" into my_header_bin for C and my_header_bin for Python.
Method and input-output mapping
The conversion follows a strict byte-wise mapping. No interpretation of file format occurs; every octet is treated identically regardless of endianness or alignment. The table below summarises the mapping.
| Input element | Processing step | Output element |
|---|---|---|
| Binary file bytes | Read sequentially as unsigned 8-bit values | 0xHH literal |
| User identifier | Replace non-alphanumeric with underscore, prefix digit with underscore | Valid language identifier |
| Line width (bytes) | Insert newline after N literals | Formatted source lines |
| Language selection | Apply syntax template | C array, C++ constexpr array, Rust [u8;N], Python bytes literal |
Units, sizing and conversion notes
Input size is measured in bytes; the resulting array length equals the file length exactly. Each hexadecimal literal occupies four characters (0xHH) plus a comma, yielding roughly five characters per input byte before line breaks. For a 64 KiB firmware image the generated source expands to approximately 320 KiB of text. Line width is expressed in bytes per source line; common choices are 8, 12 or 16. The tool records array length as a compile-time constant where the language permits (C99 flexible arrays excluded). No padding or alignment is added; the caller must handle any required alignment via attributes or linker scripts.
Limitations
Browser memory limits typically restrict practical file sizes to a few megabytes; files larger than 4 MiB may cause tab instability in some browsers. Generated source for languages requiring explicit length (Rust) includes a fixed-size array whose length is the exact byte count, which can exceed language limits on stack allocation if copied carelessly. Identifier sanitisation removes Unicode characters, so names containing non-ASCII glyphs become shorter than expected. The converter never performs compression or encoding transformations such as base64; any such requirement must be handled externally before or after conversion.
Common mistakes
Developers frequently forget to update the array length constant when the source binary changes, leading to truncated data at runtime. Supplying an identifier that collides with a language keyword (for example "class" in C++) produces invalid syntax after sanitisation fails to escape it. Selecting an excessively wide line width on very large arrays can exceed editor or compiler line-length limits. Assuming the output is null-terminated is incorrect; the array contains precisely the input bytes with no added sentinel. Finally, copying the generated text into a header without an include guard or namespace can create multiple-definition errors when the header is included from several translation units.
LONG-FORM ANSWERS
Frequently asked questions
What occurs when the binary file size exceeds the browser heap limit during conversion?
The browser tab typically becomes unresponsive or throws an out-of-memory error before any source is produced. Users should split large firmware images into smaller segments or process them on a desktop tool instead.
How does the converter treat a file whose first byte is 0x00 when generating a C identifier?
The identifier is sanitised independently of file content; a leading zero byte has no effect on the variable name. The first array element simply becomes 0x00.
Does the tool insert a length constant or only the raw array for Rust output?
Rust output always emits both the array literal and its explicit length in the type, for example [u8; 4096]. No separate constant is created.
What happens if the chosen line width is set to zero?
The tool treats zero as an invalid width and defaults to eight bytes per line to prevent infinite lines in the generated source.
Can the same binary produce both a C header and a Python module without re-uploading the file?
Yes, the original bytes remain in browser memory until the tab is closed, allowing repeated conversions to any supported language without re-selection.
How are multibyte UTF-8 characters inside an identifier handled during normalisation?
Each multibyte sequence is replaced by a single underscore, so the resulting identifier may be shorter than the original string length in characters.
Is the generated array declared static or extern by default?
No storage-class specifier is added; the array is emitted with only the requested type and name so the caller can add static, constexpr or extern as needed.
What validation is performed on the supplied identifier before emission?
Only syntactic validity is checked: the name must start with a letter or underscore and contain only alphanumerics or underscores after sanitisation. Semantic clashes with keywords are not detected.