eli5 How do people code with binary?

1.24K viewsOtherTechnology

Like I get that it can be a 1 or a 0, and that stores information, but how do you get information out of that? And how do people code with it? Seems like all it could store is numbers

Edit: Thank you all, this is very helpful

In: Technology

26 Answers

Anonymous 0 Comments

A good resource for this is Ben Eater’s youtube channel, he builds computers from scratch and you can see how all the internals work.

But for a short example: “binary” is 1 or 0, yes, but it’s really referring to on/off. For instance, the lights in your house are in “binary”, in that when they’re switched on they’re a 1, and when they’re off they’re a 0.

Now it’s possible to do more complicated things with that. We can build light switches that only turn on when two other switches are also on, or a switch that turns on when at least one of two others are on. These are called “gates”, and they do logical things—the first is an AND gate (it’s on if 1 AND 2 are), and the second is an OR gate (it’s on if 1 OR 2 are). We can also have a NOT gate, where the switch is on if one particular other switch is NOT on.

Now it turns out, we can do most calculations using these “gates”. The computer is like a gigantic house with tons of these complex switch systems, and a handful of switches that you’re allowed to touch. When we’re talking about “coding in binary”, it’s basically the same as saying “I’m going to switch some set of the lights I can touch to this particular pattern, and I want to see what other lights in the house light up”.

To make things easier over time, we’ve developed “shortcuts” that basically make it easier to understand what’s going on. For instance, we can define “1+1” to be the sequence of switches to make the computer’s “lights” light up in a way to correspond to the result of 1+1. In fact, we can make a different shortcut for + and for numbers, so that I can type into a computer “1000+230” and then that gets translated into the switches that need to be on/off to make the other lights light up in such a way that produces 1230.

As we build more and more of these shortcuts, it eventually becomes a programming language. People nowadays don’t typically code in binary—they write a programming language, which is converted in a specific way into these on/off instructions to get the computer to light up a certain way, and that “certain way” output gets translated back into things we can understand.

And again recommendation for Ben eater to get a sense of what that looks like with visuals.

Another fun way to visualize it is imagine like a pachinko board. You put marbles at the top, and they bounce to the bottom. We could build a pachinko machine that isn’t random, like say it has specific tracks where marbles put in one place are guaranteed to end up in a particular other place every time. That’s like binary code—if you put a marble in a spot it’s a 1, and if not it’s a 0. Then you let the marbles fall through the tracks, and you get some other sequence of marbles. We can assign meaning to the ending sequence because we know how the inputs produce the outputs, so it lets us do calculations and other things.

You are viewing 1 out of 26 answers, click here to view all answers.