Making Sense of Zeros and Ones in Programming

The origins of JavaScript in bytes and bits

Joe Cardillo
Coding in Simple English
3 min readJun 11, 2018

--

Photo by Mikkel Bech on Unsplash

Inside the computer’s world, there is only data. You can read data, modify data, create new data — but anything that isn’t data simply does not exist. All this data is stored as long sequences of bits and is thus fundamentally alike.

Marijn Haverbeke, Eloquent JavaScript (p. 12)

I’ve heard it said that all programming languages have their origins in zeros and ones, but what does this actually mean?

Thankfully languages like JavaScript eliminate the need to write code in binary form, but it’s still fascinating to take a look at what’s going on beneath the hood, even if only a cursory glance.

It’s also interesting to compare the origins of higher level programming languages to the building blocks of the universe. The universe, in a sense, is made up of the zeros and ones of quarks and electrons.

In the same way, all computer languages have their origins in zeros and ones.

What are 0s and 1s and how do they represent data in our computers?

The microchips in our computers contain billions of tiny on-off switches called transistors.

According to Wikipedia, “As of 2017, the largest transistor count in a commercially available single-chip processor is 19.2 billion.”

A transistor controls the flow of electrical currents.

When the current is on, it represents the number 1. When it’s off, 0.

A transistor is made of Silicon because it is a natural semi-conductor. This means it has good insulating properties and good conducting properties. In other words, it can be modified to conduct electricity really well in some conditions, or not at all in other conditions.

If Silicon has four bonded electrons in its outer shell, how does it become negatively charged?

I’m glad you asked! In its natural state, all the electrons in pure crystal Silicon are spoken for. So how can its electrons create an electrical current?

The Silicon has to be modified by adding Phosphorus, which has five electrons in its outer shell, or Boron, which has three, in order to create extra, un-bonded electrons.

If you inject a positive charge into the transistor, it will attract the negative, un-bonded electrons out of both strips of the transistor, drawing them into the tiny gap in-between. When enough electrons are gathered it creates an electrical current. If the positive charge is removed, the electrons go back into their places.

As a result, a transistor has two modes: on and off. 1 and 0.

Bytes and bits

One byte is made up of 8 bits. This means that 1 byte has 8 on or off switches. This makes 256 possible on-off combinations. (2⁸ = 256.)

A bit is either on or off, 1 or 0.

Each bit is weighted, from right to left, starting at 1 and increasing by a factor of 2.

In order to represent the number 53 in bits, we’d write it like this:

  0   0   1   1   0   1   0   1
128 64 32 16 8 4 2 1
// or 00110101
32 + 16 + 4 + 1 = 53

How do our computers interpret bytes?

If this byte were sent to the part of our computer that interprets written language, for example — called the UTF-8 code — it would interpret this as the number 5!

As you can imagine, trying to write a simple computer program — let alone a complex one — in binary form would be very error prone. This is the advantage of working with higher level languages like JavaScript.

A good programming language helps the programmer by allowing them to talk about the action that the computer has to perform on a higher level. It helps omit uninteresting details [like zeros and ones], provides convenient building blocks, …allows you to define your own building blocks, …and makes those blocks easy to compose.

Eloquent JavaScript (p. 5)

--

--