Skip to main content
Byte Array Tools

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.

Embedding 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

  1. Drop a file on the box or click to choose one. The variable name is taken from the file name.
  2. Pick the language, hex or decimal values and how many values per line.
  3. 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

No. The file is read by your browser with the FileReader API and converted on your device. It is never sent to Byteary or anywhere else.

A 2 MB file becomes more than 10 MB of source code text, which is already slow to paste, edit and compile. For larger files, load them at runtime or use your build tool's resource embedding (for example include_bytes! in Rust or go:embed in Go).

The C output is equivalent to xxd -i: an unsigned char array of hex bytes. You can also choose other languages, decimal values and the number of values per line. xxd -i additionally writes a length variable; in C you can use sizeof(array) instead.

Add the PROGMEM keyword and make the array const, for example const unsigned char logo[] PROGMEM = { ... }, then read it with pgm_read_byte. Otherwise the array is copied into the limited RAM at startup.
Share this tool: