Understand Binary in Bits & Bytes

Understand Binary in Bits & Bytes

A brief intro to binary numbers. Base-2 vs. base-10 number systems.The internal workings of binary in computers.

Introduction

Hello! Developers. Have you ever thought about behind the screens we interact with daily, a secret language of 0s and 1s called binary resides within the computer's memory?

In this article, We will explore the fundamental concepts behind binary code, understand how it is represented in RAM, and gain insights into the inner workings of future software engineers.

Behind the screen of computer memory

Random access memory (RAM) is the best-known form of computer memory.
RAM is your computer's short-term memory or volatile memory. This means it will be lost its data stored in it when it loses an electrical power supply.

Ram is a memory chip that is an integrated circuit (IC) made of millions of transistors and capacitors. Now you may get a question about how a transistor stores data.

Transistor

A Transistor and a Capacitor are paired to create a memory cell, which represents a single bit of data. The capacitor holds the bit of information 0 or 1. The explanation of the inner working is beyond the scope of this article to know more check out this article. How does RAM work?

For example

Let's consider a graph with some threshold value. If the power on that certain cell is more than the threshold value it 1. If it is less than that threshold it is considered as 0.

I hope that this above image helps to understand the idea behind storing the binary data using a Transistor & Capacitor. We can also consider that as an ON & OFF state.

Why do we need Binary?

I believe you may get that as we are using Transistor & Capacitor. We cannot directly store a decimal number or value in memory. Because we have only two states 0 & 1 can be stored. So, we need to find a way to store information within these two states. That's where we need a Binary number system.

This leads us to a very interesting question. As humans, we cannot read binary & understand. So, we have to convert human-readable values to Binary. How to do a Binary conversation?

Solve this Problem

Before Jumping into the binary conversation try to solve the below problem for better understanding.

Let's consider we have a total of 31 grams of gold. And we have to cast or separate it only as 5 coins. If we sum the weight of 5 gold coins it should not be more than 31 grams. Now we have to give that gold coins to a person based on the day he comes to the shop.

For example:

If he comes on the 8th day of the month. we need to give him a 8-grams of gold. As same, if he comes on the 25th day of the month. we need to give him 25- grams of gold.

Post your answers in a comment section.

Solution

The answer is casting the 31-grams into 1,2,4,8,16-grams.So, we can form any combination from 1 - 31.

For example:

DayCombination
71,2,4
124,8
151,2,4,8
248,16
311,2,4,8,16

Explanation

I hope you can see that the solution has a patter of powers of 2.We are going to use this idea to convert decimal to binary numbers.Look after the bellow table to confrim the solution follows the pattern powers of 2.

PowersOutput
2^01
2^12
2^24
2^38
2^416

I hope that now the problem makes sense to understand the binary to the core.Before diving into the converstion,We need to get a knowledge about the some basic computers terms.

Terms to understand

What is a Bit?

A bit (binary digit) is the smallest unit of data that a computer can process and store.The bit is represent a by a single binary value, usually a 0 or 1.

What is Byte?

A byte is a sequence of eight bits that are treated as a single unit.The byte referencing to a computer's memory and storage.

For example

A storage device might be able to store 1 Mega byte (MB) of data.Then 1 MB equals 1 million bytes, or 8 million bits.

I belive now you undertand about a bit & byte in computers.Let's dive more deeply to undertsand how does it acutally store the decimal & data into binary.

How does a bit works?

Each bit in a byte is assigned a specific value, which is referred to as the place value. A byte's place values are used to determine the meaning of the byte as a whole, based on the individual bits.

It seem's like more complicated task.Let me explain it through the problem we have solved before & with a knowledge of bit & byte.

On the example problem we have got 5 coins to caste.Let consider that 5 coins as 5 bits.The representaion will be like image below.

A place value is assigned to each bit in a right-to-left pattern, starting with 1 and increasing the value by doubling it for each bit.

Now, We can make the place value of 0 to 1 to make a combination of number from 1 - 31.As shown in image below.

So , The with help of 4 bits we can store maximum value of 31.This process follows for 8 bits.

Bit position (right to left)

Place value

Bit 1

1

Bit 2

2

Bit 3

4

Bit 4

8

Bit 5

16

Bit 6

32

Bit 7

64

Bit 8

128

A single byte can support up to 256 unique characters, starting with the 00000000 byte and ending with the 11111111 byte. The various combinations of bit patterns provide a range of 0 to 255.

This is how the bit works internally to store the value.Now you may have a question for numbers it make sence.What about the alphabets & special Characters?.The alphabets & special characters has ASCII code.

What is ASCII code?

ASCII (American Standard Code for Information Interchange) is the most common character encoding. ASCII is an encoding representing each typed English character by a number.

Ex: A is 65 (01000001 in binary).

Bytes and Characters - ASCII code:

The below image represents ASCII code followed by character.

For example, the uppercase "S" in the American Standard Code for Information Interchange (ASCII) character set is assigned the decimal value of 83, which is equivalent to the binary value of 01010011.

That't it. i belive now you got an idea of how does your computer works behined the scenes using binary.There are also some other respresentaion like hexadecimal numbers.

Conclusion

So, armed with the knowledge gained from this exploration, let us continue to unravel the mysteries of bitwise operations.

I hope you got valuable information today. For more content like this like & share in your communities.

Did you find this article valuable?

Support Saravana Sai by becoming a sponsor. Any amount is appreciated!