Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

How Much Data Can You Print On A Piece Of Paper?

Head's Up

This piece ended up being split into two thing. The other part is

They Got Me

I got nerd-snipped^ns^^.

OK, here's a fun nerd-snipe. How much data can you fit on a piece of A4 paper? In what format? I imagine it would be something like a mega QR code, at whatever the best resolution that common optics can differentiate, with some sort of compression involved. But I can't come up with an actual number.

-- Jeff Darcy (Mastodon)

I saw a post years ago that answered that question. I didn't look it up, though. It was all theoretical. I wanted to try it myself and see.

Encoding The Problem

Computers don't read or write the way we do. For example, when a computer saves a file with the text "Hello, World" it does so without using any letters. In fact, it only uses two numbers: zero and one. Or, better said, it uses lots and lots of zeros and ones without needing anything else.

This blew my mind when I first learned it. It still amazes me even though I've been working with computers for decades. Computers aren't magic, but they can do things that seem magical including doing everything they do with just those two numbers. It has never ceased to amaze me.

It Starts With A Switch

Before we talk about ones and zeros, let's look at a regular light switch, like this one:

The switch can be either on or off. Click/tap it and you'll see that when switch is "On" the light lights up. When the switch is "Off", so's the light. We can also have more than one switch. Each one connected to its own light so you can turn them on or off in any combination you want.

Computers uses switches too. They're microscopic and work with electrical signals instead of pressing them up and down but the fundamental nature of switching on/off is the same.

The biggest difference is that computer switches aren't attached direclty to things like lights be default. Instead, they are used to keep track of those ones and zeros we mentioned earlier.

The Computer Switch

Imagine a tiny wall inside a computer with a ligth switch on it, but instead of being attached to a light it's attached to a sign above it that displayed either a zero or a one.

Something like this:

You can click it on and off to change the number back and forth, but it doesn't really do anything else. The number doesn't mean anything by itself. That's where apps come in.

TKTKTKT

Let's build some mini-app buttons for examples of working with the switches. The first one we'll build is a button that just displays with same zero or one that the switch is showing.

To help keep things separated, I'm going to split our app into a view of the main area that we'll interact with and then a "Behind-the-scenes" area that shows what the computer and app are doing in the background.

The Do Nothing App

For our first app, we'll make a single button that doesn't do anything. The purpose here is to get a first look at the layout we'll use for the rest of the examples before we start adding things to them.

The layout is split into two parts:

  • "Mini-App Screen" which represents what we'd see using the app

  • "Behind-The-Scenes" which shows what the computer is doing in the background that we normally wouldn't see

The Show Me App

Let's make a button that does something. Specifically, let's add a switch behind the scenes and have the button toggle it and display it's value when we click it.

Here's an overview of the process of putting thing together.

  • We know that we want to display the one or zero value from a switch so the first thing the app does is send a signal to the computer requesting one. The computer adds one Behind-The-Scenes and gives the Mini-App control of it.

  • The Mini-App can do two thing with the switch: 1) Read it's current value, and 2) Flip the switch to change the value.

  • Our switch starts out in the "Off" position displaying a zero. The Mini-App sees that and updates the text of inside the button to say "Switch is currently: 0".

  • When we click the button, the Mini-App sends a signal to the switch to swtich from whatever number it's current on the other one (aka toggling). So, when the switch is "Off" and displaying a Zero, it toggles it to "On" and displays a One. If the switch is "On" (and showing a One) when the button is clicked it turns to "Off" and displays a Zero.

  • After the Mini-App toggles the switch Behind-The-Scenes it reads the number and updates the text inside the button.

Adding Color

The Behind-The-Scenes switch only has two possible positions:

Off which displays Zero

and

On which displays One

But, we don't have to _show__ a Zero or a One. Instead, we can use Zero and One to _represent__ more interesting things. For example, let's make a Mini-App where the button changes color between Brown and Blue. We'll use the same Behind-The-Scenes switch as before, but this time when the Mini-App reads it and sees a Zero, it'll display Brown and when it sees a One it'll display Blue.

Multiple Buttons

So far, we've been using one button to both change and read the value of our switch. This doesn't have to be the case. We can have two buttons work with the same switch at the same time. For example, let's make a Mini-App with two buttons and a status message.

The buttons will be "Toggle Switch" and "Display Value". Clicking "Toggle Switch" will flip the Behind-The-Scenes switch back and forth but won't change anything on the Main-App Screen. To do that, we'll press "Display Value" which will get the current value from the switch and display it in on a status line.

Counting

Computers also use switches for counting. Each switch can only have a Zero or a One so counting is done by adding more switches. The first way we can do this is to count the number of swtichs that are on.

To start with, let's add four buttons that are connected to four switches. We'll label the swithces with letters to make them easier to keep track of

A Single Press App

Let's make a sample app here called "Did I Press The Button?" that has two buttons on it. One that says "Press Me!" and another that says "Has the button been pressed?".

When we start our app (or refresh this page), we'll display a status message with question marks that get updated when we press the "Has the button been pressed?" button with an appropriate response. (i.e. it'll tell is if we've pressed the main button yet or not)

Behind the scenes the app needs to keep track of if we've pressed the main button or not. This is where we get to start using our switch. The setup process looks something like this:

  • The app signals to the computer that it would like to use a switch on our imaginary wall to keep track of if the main button has been pressed or not.

  • For now, let's imagine there's only one swtich on the wall and the computer isn't using it for anything else so it says "sure" and tells the app it can turn the switch on and off however it wants.

  • The programmer who wrote the app decided that if the main button hasn't been pressed yet the switch should be set to "Off" (which means it's displaying a zero). So, when the app first starts it makes sure the flip the switch off.

Functional Buttons

Now that the app is running we can press each of the buttons to see what happens.

single "Press Me!" button and a display that says if the button has been pressed yet or not. When we first launch the app, the button hasn't been pressed so the message reflects that. When we press the button, the app

Unlike our human light switch that does something specific (i.e. turning a light on or off) in the real world, switches in a computer aren't connected to anything by default. They way they get used is by apps which run on the computer

Now, instead of a putting a light above it, let's use numbers. Specifically, we'll use a zero when the switch is "Off" and a one when it's "On".

What's A One? What's A Zero?

Now, what do we do with this new power to change between a one and a zero.

The first step to storing data is to convert it from something we humans can understand into something computers can work with. Let's say you have a file

At it's most basic the problem comes down to storing data on a piece of paper instead of a hard drive. No matter where data is getting stored (hard drive, paper, or something else) the first step is to transform it from something we humans can understand into something the computer can work with.

The Colors

It's easy enough to come up with some numbers. The first thing to do is

You could, for example, start a calculation from an "8-bit image". Bascially, a photo where the color of each pixel is made by mixing 256 shades of red with 256 each of green and blue. Multiply the numbers to deteremine the total number of combinations and you get

256 x 256 x 256 = 16,777,216 colors

The Pixels

References