Abstraction in programming: Taming the ones and zeros

by -270 views

The origins of JavaScript in bytes and bits

Photo by Mikkel Bech on Unsplash

Within the calculator’s earth, there is just information. You can read data, modify data, create new data — only anything that isn’t information simply does non be. All this information 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 take their origins in zeros and ones, simply what does this actually hateful?

Thankfully languages similar JavaScript eliminate the demand to write code in binary form, simply it’southward still fascinating to have a look at what’s going on beneath the hood, even if only a cursory glance.

It’southward 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 style, all estimator 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.ii billion.”

A transistor controls the flow of electrical currents.

When the current is on, information technology represents the number one. When information technology’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 tin can be modified to carry electricity actually well in some conditions, or not at all in other weather condition.

If Silicon has iv bonded electrons in its outer trounce, how does it get negatively charged?

I’thousand glad you asked! In its natural country, 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 v electrons in its outer shell, or Boron, which has three, in guild to create extra, un-bonded electrons.

If you inject a positive accuse 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 electric electric current. If the positive charge is removed, the electrons go dorsum into their places.

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

Bytes and $.25

Ane byte is made up of 8 $.25. This means that 1 byte has 8 on or off switches. This makes 256 possible on-off combinations. (ii⁸ = 256.)

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

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

In order to stand for the number 53 in bits, we’d write it similar this:

          0   0   1   ane   0   1   0   1
128 64 32 16 viii 4 ii 1
// or 00110101
32 + sixteen + iv + i = 53

How do our computers translate bytes?

If this byte were sent to the function of our calculator that interprets written language, for example — chosen the UTF-8 code — it would interpret this equally the number v!

Every bit you lot can imagine, trying to write a simple figurer program — allow alone a complex ane — in binary grade would be very error prone. This is the advantage of working with higher level languages like JavaScript.

A good programming linguistic communication helps the developer past 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 y’all to define your own building blocks, …and makes those blocks piece of cake to etch.

— Eloquent JavaScript (p. five)

Source: https://medium.com/coding-in-simple-english/making-sense-of-zeros-and-ones-in-programming-701d84c4cbe0