Better Programming

Advice for programmers.

Follow publication

How Does Binary Code Work?

No one talks about it!

Vishal Sharma
Better Programming
Published in
4 min readJun 25, 2020

--

Photo by Markus Spiske on Unsplash

There are 10 types of people in this world — those who understand binary and those who don’t!

We’re intensely involved in applications, interfaces, social media — in a word, technology. We watch movies for entertainment, explore maps for direction, and every word you are seeing on your screen right now. What is it? How are they generated? How do they look like at their most granular stage?

Only 1s and 0s! Just imagine seeing it all just as millions of 1s and 0s. Nerve-wracking, right? But, it’s the truth. At the granular level, all we are seeing on our computer screen are 1s and 0s.

Computers use binary to store data. Not only because it’s a reliable way of storing the data, but computers only understand 1s and 0s — binary. A computer’s main memory consists of transistors that switch between high and low voltage levels — sometimes 5V, sometimes 0. That reading is done by the computer’s processor which reads the transistor state — high or low — to control the computer’s other devices, according to software instructions.

Binary Numbers and Text

Binary data has no predetermined meaning on its own. Instead, each type of data is encoded in the binary format according to a separate set of rules.

For example, the number 10 will be represented as 1*10¹ + 0*10⁰ in decimal format. It will make up to 10. While the same digit is represented as 1010 in binary. In binary, each digit is raised by the power of 2. Hence, 10 in binary is formed by 1*2³ + 0*2² + 1*2¹ + 0*2⁰.

When it comes to letters, they’re defined by the rules set by UTF-8, which assigns each character a group of 8 binary digits:

Alphabets Binary code — Pinterest

So, the name “JOHN” will look like this in binary code:

J: 1001010, O: 1001111, H: 1001000, and N: 1001110

Context is Important

Take “H” from the word JOHN. It also represents 72 in decimal. So, how does the computer understand whether it is a letter “H” or decimal number 72? It all comes down to context!

For example, the Spanish term for frog is “rana,” but rana means, ”wound” in Romanian and Bulgarian. Now, if we know the context, i.e the language, we will know what rana means.

Similarly, we need a context to understand whether we are looking at binary numbers or text.

Binary is a Source of Complex Data Too!

Pictures and videos

It’s not only numbers and text — binary is used for the most complex data. From images to video frames, at the most granular level of the data, it is binary code.

For example, an image is built up of hundreds of thousands of pixels, with each pixel containing an RGB value stored in binary code.

These binary codes fill RGB and according to the intensity generated from those codes, the intensity numbers are thrown at a video driver program. That program distributes those colors to the million crystals on your screen — and an image is seen by us!

Sound

What about our favorite song? That too is stored in binary format, using a technique called pulse code modulation. Continous soundwaves are digitized by taking snapshots of their amplitudes every few milliseconds. Those amplitudes are stored as numbers in binary. Each second of sound can have around 44,000 binary strings. When these numbers are read by our computer software, the numbers determine the frequency of vibration in the coils of the speaker to create sounds of different frequencies.

Summary

It all requires billions and trillions of bits. We understand binary is the atom of every data we read and see. But, is binary the be-all-end-all of computing? No!

Scientists have researched ternary computers with circuits in three possible states — 0,1, and 2. Quantum computers even exist these days, whose circuits can be in multiple states simultaneously. So far, nothing has rocked like binary for storage and transmissions in computers.

Next time, whether you are reading an e-book, watching a movie, or listening to a song on your laptop, just remember everything comes to from the source of true or false — 1 or 0, billions of times over!

Peace!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Responses (1)