Binary Codes & Puzzles

How to Make Binary Code Art with Text and Pixels

Make binary code art with a decodable text message or a two-color pixel grid, and learn how to preserve byte order and alignment.

Binary Translator
  • ASCII
  • Pixel Art
  • Binary Messages
On this page

The distinction between decorative digits used as visual marks, pixel digits that select colors, and encoded text that carries a message is key to understanding binary code art.

Binary code art is often presented in one of two forms: image-to-character art (also called “light and dark pixels mapped directly to 0s and 1s”) or as an encoded message (in which bits represent characters from the ASCII alphabet). In either case, the interpretation of the digits depends on what the creator wants the audience to see.

Encoding Text in Binary

One way to think about binary art is in terms of how we convert letters and numbers into binary digits. This process involves encoding each character into an eight-bit byte. For example, the letter A can be represented by 01000001 in binary, and so on for every other letter, number, and common symbol.

In our case, we’re not going to use any of these conventions, because it’s just easier to preserve all of the digits. That said, the basic idea remains the same. Let’s take an example of a very short original message:

Original message: ART

Convert this to binary:

ART → 01000001 01010010 01010100

If I wanted to encode this message in another format, say, an image, I could create an arrangement where I would place the digits in their exact order. Here, I have preserved all of the digits intact, grouped them by eight, and arranged them left-to-right within each line. Lines are top-to-bottom. When reconstructing the text, I can simply decode the binary digits back into text using a translator such as the site’s browser-based Text to Binary translator. I select eight-bit output when converting ART, then paste the arranged binary back into the translator for binary-to-text conversion. The recovered text should match ART exactly.

Five-by-five pixel grid with arrows showing left-to-right and top-to-bottom reading order.

Creating a Binary Pixel Grid

Now you might be thinking: “That looks like a lot of work.” But let me show you a much simpler approach, using only the digits that we need, and without needing to worry about preserving the complete bytes. Just keep in mind that you will lose the ability to recover the original text exactly when you do this.

Let’s begin by creating an image of our own, composed entirely of colored squares, using the documented classroom color convention. We’ll create five columns and five rows. Each row must be recorded left-to-right; rows are then listed top-to-bottom.

Using the documented classroom color convention, here is the pixel grid.

Row 1: 01110

Row 2: 10101

Row 3: 11011

Row 4: 10101

Row 5: 01110

Here, 0 means black (■) and 1 means white (□). The matching picture looks like this:

■□□□■
□■□■□
□□■□□
□■□■□
■□□□■

As you can see, the answer-key symbols match up exactly with the pixels chosen above.

This project uses the same principles that appear in CS Unplugged’s classroom activity: graph-paper image, record the binary digits you chose, and then pass your paper to someone else to try and reconstruct the picture you created.

Information Needed to Recreate the Image

So why did we choose to represent these pixels as groups of five? Because they represent the color choices made during the creation of the image. The information necessary to recreate this image includes more than a raw grid: the dimensions of the image, the mapping of each color choice to its corresponding binary digit, and the reading order of the digits within the image.

In a complete image format, additional information may also be stored: the width and height of the image, the individual color values at each index, the bits per run, and even a file signature header.

Documented Browser Styling

It should go without saying that preserving alignment while formatting the binary output is important. To that end, you can apply the following CSS styles:

font-family: monospace;

all glyphs given the same fixed width

white-space: pre;

spaces and explicit line breaks preserved

line breaks only at source newlines and <br> elements

no automatic wrapping

Fixed glyph width does not necessarily imply square cells, which means that you must always inspect the destination’s rendering before sharing any content. What’s rendered via the browser will behave differently from what’s displayed in your messaging app of choice.

You can test out this CSS styling yourself.

Sources