Even if you are not an expert in programming or Computer Science, you probably know that computers only possess a very limited vocabulary. The alphabet every computer in the world understands is binary code, that cryptic, seemingly never-ending sequence of 1’s and 0’s.

In today’s post, I’m sharing what I have learned about how these simple 1’s and 0’s make our tech-filled world go round. In short, they are the backbone of what is happening in your computer all the time. Therefore, having a basic understanding of what binary code is and how it works helps you understand how your computer works on the inside.

So if you are new to coding, pair this post with my Free Coding Guide for Beginners and you’re good to go!

Let’s get to it! Happy reading!


Why should I understand how binary code works?

But if binary code is something only computers understand, why should you learn more about it?

You are absolutely right – you will (most probably) never write a computer programs in binary code. Instead, developers like you and I use other, more user-friendly programming languages to give instructions to computers.

Nevertheless, binary code is probably the most fundamental concept underlying programming and Computer Science. It is what makes every computer you use work the way it does.

All in all, binary code enables us to communicate with computers and give them instructions. And even though the programming languages you use for writing code are hopefully far from binary code, they are still translated into binary for computers to be able to interpret them and run your programs.

Hence, binary code plays a big role in how computers work on the inside.

Those 1’s and 0’s define how computers take inputs, store and process information, as well as produce outputs for their users – that’s you and me.

Thus, understanding at least the basics of what binary is and how it works is not only interesting and quite fascinating, but also quite useful.

— Read also: Learning Computer Science Basics Before Coding

But don’t worry if the concept of binary code seems abstract and difficult to grasp at first. What matters is that you are aware of how such a simple language can translate into the most complex computer programs and information structures that you see and use on a daily basis.


Learning coding and web development

What’s up with the 1’s and 0’s?

So how does binary work then? How can a complex computer program consist of only 1’s and 0’s?

To simplify things just a little bit, you can think of binary as being a way of telling a computer whether a switch should be on or off. Thus, 1 means “on”, 0 means “off”.

But wait a minute – what kind of a switch are we talking about here?

How does a switch that is either on or off translate into what computers can do for us these days?

To shed some more light on this, let’s briefly think about what computers do. Simply put,

  1. computers take inputs from their users,
  2. store and process them as information, and
  3. finally provide their users with outputs of various kinds.

For example, when you’re typing on your computer, your fingers hitting the keyboard are providing your computer with some input. Then, your computer magically knows how to translate certain keys into the desired letters and text. Finally, the output from your computer is the text it displays on your screen.

So what does this have to do with binary code?


What do computers do with all the 1’s and 0’s?

Those 1’s and 0’s, or the switches I mentioned above, are how your computer stores and processes data.

Back in the day when the very first computers were built, they had actual lights bulbs to provide outputs to their users. So a user would see a certain light switched on to indicate a certain kind of output or message from the computer.

The same thing happens nowadays when you are driving your car and the gas light comes on. That is an output from your car, telling that you should get off the freeway and find a gas station asap.

So with a computer, these 1’s and 0’s can be pretty much anything in modern computers. But generally they represent numbers, letters, and other symbols.

The bottom line here is that this simple concept of a switch being on or off can translate into something really complex.

Even the most sophisticated, modern computers all work according to this very basic, rudimentary machine language with the 1’s and 0’s representing two states: either on or off. But to make this happen, your computer obviously deals with a lot more than just a single switch being turned on or off.


Laptop with code

How do computers store information?

Before we dive into how binary code and binary numbers actually work and how you can decode a simple binary sequence, let’s consider one fundamental point about data storage first.

As I mentioned above, computers take inputs to store and process information. This information or data is the fundamental ingredient for any computer to work.

Now, when you look inside a computer, you will see a bunch of circuits and electric wires. They carry all the information inside a computer, getting it to the right place to be either stored or processed.

But how do you store or represent information using electricity?

Now, the 1’s and 0’s we were just discussing represent the smallest unit of data that a computer understands.

One switch being either on or off is what we need to store one bit of data.

Hence, a bit is the fundamental, basic unit of information. It is enough to indicate two different options, either “on” or “off”. Also, it could mean “true” or “false”, or simply “yes” or “no”.

I know, having just two choices does not give us too many options really… But it is a good start!

With one light bulb we can store 1 bit of information. With 10 light bulbs, we could do 10 bits. So, if we had enough light bulbs, we could store any amount of data we wanted in a digital form.

Storing data in bits: a simple example

Of course, computers use other methods and technologies than simple light bulbs to store data these days. Using light bulbs would not only take up too much space but it would also be difficult to store the data: turning off a computer using only light bulbs would mean that we would lose the data when the power goes off.

Thus, instead of light bulbs, computers store bits of data by holding electrons in capacitors, for example. Your computer uses this technology in its DRAM memory.

So, how many light bulbs would fit into your DRAM exactly?

Let’s assume your computer has a 4GB DRAM, for example. One GB is approximately a billion bytes. Or to be more exact, 1 GB is 230 bytes. And 1 byte = 8 bits.

That means your 4GB of DRAM holds 230 x 4 x 8 = 34,359,738,368 bits. That’s 34 billion light bulbs – and we are only talking about your DRAM here, not your 1TB hard drive!

So it’s quite obvious that modern computers can do much more than decide whether to switch on a single light or not. Thus, even though binary code consists of only 1’s and 0’s, it can represent the most complex of computer programs these days.


Computer hard drive on a table

How does the binary number system work?

Now, what does it mean to have 34 billion bits to store and represent information?

To understand what these bits can do for us, let’s take a closer look the binary number system. It only uses 0’s and 1’s to represent any further numeral values – and other types of data, too.

First, let’s do a quick refresher on how the “normal” numbers that we are used to work.

Namely, the numbers you and I learned in school, ranging from 0 to 9, make up the decimal number system. You can use any combination of these 10 digits to represent a numeral value. Moreover, you know how to do additions, subtractions, and other basic calculus using these numbers relatively quickly.

In the decimal system, each digit in a certain number represents the 1’s, the 10’s, the 100’s, and so on, starting from the right hand side.

So, with the number “216”, for example, we have a 6 representing the 1’s, a 1 representing the 10’s, and finally a 2 to represent the 100’s:
Binary code and binary number system explained: a simple example

The decimal system uses powers of 10 to differentiate between these three “levels” of digits:

  • 1’s: the 1’s represent how many times the numeric value includes 100
  • 10’s: the 10’s stand for 101
  • 100’s: the 100’s represent 102

So you see the pattern here? 10 to the power of 0, 1, 2, and so on. We simply keep increasing the powers of 10 as our number gets bigger. Therefore, the decimal system is also called the base-ten numeral system.

And for my dear, fellow language nerds: the word decimal comes from the Latin word decem for “ten”, while “binary” is derived from the Latin word bi, meaning “two” as a prefix.

How to “decode” a binary number?

In the binary system, instead of using powers of 10, we use powers of 2. 

So, similarly to the decimal example above, let’s think about what the different positions in a number mean. Assuming we have a binary number with several digits, we can start from the right hand side again:

  1. First digit stands for 20, so these are the 1’s
  2. Second digit: 21, these are the 2’s
  3. Third digit: 22, these are the 4’s
  4. Fourth digit: 23, these are the 8’s
  5. Fifth digit: 24, these are the 16’s
  6. Sixth digit: 25, these are the 32’s
  7. Seventh digit: 26, these are the 64’s
  8. Eighth digit: 27, these are the 128’s
  9. Ninth digit: 28, these are the 256’s
  10. etc.

Unlike in the decimal system, here in binary each of these digits simply tells us whether the digit is “on” or “off”. When you see a “1”, it means that the value of that digit is included in the numerical value that we wish to represent.

Binary numbers decoded: a simple example

So how would we represent the number we just saw in decimal notation, 216, in binary?

Let’s give it a go!

  1. Firstly, let’s start by looking at the powers of 2 in the list above. We need to find the largest value that is less than the value of 216.
  2. We see that it is the 128’s, so we need 8 binary digits in this case, from 20 to 27. You can see these 8 spots in the image below.
  3. Since 128 is “included” in our number, let’s indicate this by a “1” in the 128’s place in the image below.
  4. Then, let’s do a simple subtraction: 216 – 128 = 88.
  5. Again, let’s repeat the first step and find the largest value that is less than this leftover of 88. We see it is the 64’s, so we put a “1” in the digit for 26.
  6. Now, let’s subtract again: 88 – 64 = 24.
  7. So, going back to the first step we see that the next digit we will need to use a “1” for, is the 16’s place, or 24.
  8. We simply keep repeating these steps for finding out which binary digits get a value of either “1” or “0”.

Finally, we end up with the following binary sequence: 11011000. As such, it doesn’t really mean anything to you and me, since we are not used to the binary system.

Let’s calculate the values for the powers of two for each digit and add them together:

Binary code and binary number system explained

So, we end up with the correct number that we wanted to display in binary.

Great success!

Clearly, we do need a few more digits than we did with the decimal system, but the value of the number is exactly the same. And that is all that matters!

Thinking and calculating in binary numbers is of course somewhat tricky, since we are used to a number system based on the powers of 10.

But all in all, even though the fundamental idea of having just two states representing two values, either “on” or “off”, the binary system is just as good as the decimal system for displaying numbers.

But how about other sorts of information, like text, images, or audio?

Well, as it turns out, all of these types of information can also be represented in binary, too!

Text in binary

With binary, we can use simple numbers to represent the different letters in the alphabet. So “A” could be “1”, “B” could be “2”, and so on.

That way, we can represent any word or paragraph of text as a sequence of these numbers. A computer can then store these numbers as information using the “on” or “off” signals.

So whenever you are reading text on your phone or your computer, what you see on your screen is based on a system like this.

Images and graphics in binary

In a similar way to representing the alphabet in numbers, we can do the same thing for images and other graphic media, too.

An image displayed on your screen consists of pixels. Each pixel in an image has a numerical value that determines the color it should display.

Considering a single image can be made of millions of pixels, we’re talking about a huge amount of information here!


Summary: Binary Code Explained

I hope you are still with me!

I know this topic is somewhat abstract and it might be difficult to think of a situation where you would need to know how the binary system works. When you are writing code and creating programs for your computer to execute, you are not dealing with these binary numbers directly, really.

However, you will be dealing with what all these 1’s and 0’s can do for you. You write and read text, create and see images, and watch videos and other media on your computer.

Therefore, knowing how binary code works and what the binary system really means can help you understand how computers work on the inside. They are the fundamental building block of everything your computer does: getting input, storing and processing information, and producing output.

So, no matter how complex or sophisticated a computer program or system is, it all comes down to these simple 1’s and 0’s.

I hope you found this post helpful! Please feel free to share your thoughts and ideas in the comments below, and stay tuned for more Computer Science 101 posts!

HI THERE!

HOW ABOUT A FREE E-BOOK?

Sign up now and get 15 awesome tips for learning coding more quickly and easily!

Yay, thanks for subscribing! Please check your email to confirm your subscription and to receive your download link.

Share This