DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Laura Beatris
Laura Beatris

Posted on

Binary in a nutshell

There are only 10 types of people in the world: Those who understand binary and those who don't

The sense of curiosity

When I got my first computer, I couldn't know at first that the Mario that I was seeing on my screen was actually composed of a bunch of 0s and 1s - How come silly combinations of numbers can handle the magic behind video games and web applications?

image

Systems of counting

Along the years, as civilizations started to grow, many systems of counting (Or numeral systems) were created, such as:

  • Tally marks
  • Base ten positional β†’ Decimal system
  • Base two positional β†’ Binary system

image

What is binary?

Binary is a numeral system based o two digits (0 and 1), which represents numbers based with a base of 2. It's used to write binary code which is the "language" to communicate instructions to a computer processor.

In a nutshell:

  • Uses base 2
  • Greater than 1 β†’ New digit
  • Extremely useful for electricity

image

Why to use binary instead of decimal?

Humans decided to use decimal mainly because it's easier to demonstrate multiple combinations of values and it's also more high level in a way that makes it easier to read and exchange information.
Therefore, the decision to use binary for computer hardware is due to reasons related to physics and data processing.

  • Simplicity: It's easier and simpler to rely on two states of characters in order to perform processing, than having to deal with a huge amount of combinations.
  • Electricity integrations: As mentioned previously about combinations of numbers, having just 0s and 1s, easily enables to detect of electrical signals such as off (false) and on (true)
  • Magnetism: Binary can be represented via positive and negative poles of magnetic media and in fact, this is how hard disks works in order to store data in a non-volatile way.
  • Circuits control: Circuits contain switches with control logical flows via electrical signals and binary is the most efficient system to accomplish so.

Characters representations

Now that the definition of binary and its use cases are clarified, you might be wondering how letters and other characters are displayed in software since all data is stored with 0s and 1s on the computer memory.

There are many things to consider, such as each language has a variety of characters to be supported - and also the first computer creators didn't expect that someday we would use things such as emojis. Consequently, along the years, many encoding systems from decimal numbers to other representations have arisen.

Examples of encodings:

image

How binary is stored on memory?

Consider the following main mechanisms for data storage:

  • RAM (Volatile)
  • HDD (Non-volatile)
  • SSD (Non-volatile)

Each of the above handles binary data in a different way. Let's start from RAM:

RAM

Stores binary data through capacitors, which contain two states when interacting with electricity:

  • Charged: 1
  • Un-charged: 0

Each "0" and "1" is considered a bit and 8 bits lead to 1 byte. Typically, a computer have 8 gigabytes of memory and consensually, 8X8e+9 or (64 billion) RAM memory cells.

image

HDD

Stores binary data through magnetic lines from a spinning metal disk called as "platter" and it's covered by magnetic material.

A read/write head that contains an electromagnet on its tip, enables to write magnetically charged lines on the surface of the platter. When reading, if a line is magnetically attractive it is considered a "0" and if it's repulsive, then it's considered a "1".

image

SSD

Stores binary data through transistors, which contain two states when interacting with electricity:

  • Charged: 1
  • Un-charged: 0

Unlike RAM capacitors, transistors are able to keep their charge even after powering off a computer, leading to not data-lost.

Conclusion

Binary code allows representing physical states via abstractions with 0's and 1's. Used with the following mechanisms:

  • RAM: Electric charge with capacitors
  • HDD: Magnetic charge with lines
  • SSD: Electric change with transistors

Resources


Thanks for reading so far. I would like to mention that I'm planning to do a series of blog posts of topics related to CS fundamentals.

The goal is not to go too deep into these topics but to try to give a quick summary with higher-level concepts (And that's why I named the title of this post with "In a nutshell").

Top comments (1)

Collapse
 
elianbecali profile image
Elian Becali

Very good! πŸ˜‰

🌚 Turn on dark mode

πŸ”  Change your default font

πŸ“š Adjust your experience level to see more relevant content

Β 

Head to your account's Settings to do all this and more.