File to Byte Array Converter
Convert any file - an image, font, certificate or firmware blob - into a byte array for C, C++, Java, C#, Python, Go, Rust, JavaScript or PHP. The file never leaves your browser.
Choose a file to embed it in source code as a byte array - the file is read by your browser and never uploaded.
Drag & drop any file here, or click to choose
Up to 2 MB - larger arrays are impractical to paste into source code
The file is read by your browser and never uploaded.
More Byte Array Tools
View all 17Embedding files in code makes binaries bigger and recompiles slower - for large assets, load the file at runtime instead.
What Is the File to Byte Array Converter?
It converts any file into a byte array you can paste into source code - the same job as the xxd -i command or "bin2c" utilities. Choose a C/C++ unsigned char array, a Java or Kotlin byte array, a C# byte[], Python bytes, a JavaScript Uint8Array, a Go []byte, a Rust [u8; N], a PHP array or JSON.
When to Use It
- Embedding an icon, font or sound in firmware for a microcontroller such as an Arduino or ESP32.
- Putting a small test file, certificate or key fixture directly into a unit test.
- Shipping a tiny asset inside a single-file program.
How to Use It
- Drop a file on the box or click to choose one. The variable name is taken from the file name.
- Pick the language, hex or decimal values and how many values per line.
- Copy the array or download it as a source file.
Example
A PNG image named sample-image.png becomes unsigned char sample_image[] = { 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D, .... The first eight bytes are the PNG signature, which is why every PNG array starts the same way.
Understanding the Output
The status line shows the file size and, when it can be recognised, the file type. In C, sizeof(sample_image) gives the length; in Rust the length is part of the type. Java and Kotlin arrays use casts or negative values for bytes above 127, because their bytes are signed.
Limitations
Files are limited to 2 MB: a larger array produces megabytes of source text that editors and compilers handle badly. For bigger files, load them at runtime or use your build system's resource embedding. The file is read in your browser and never uploaded. To turn an array back into a file, use Byte Array to File; to inspect a file first, open it in the Hex Viewer.
Frequently Asked Questions
Explore More Tools
Keep going with related categories and our most used tools.