How to Convert Binary to Decimal (and Vice Versa)



Humans invented over 100 different ways to write numbers over the past five and a half millennia.

With regard to Roman numerals, the world’s preferred technology at the moment – by a large margin – is the modern decimal system. Its users can express any whole number with just 10 lowercase letters: 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9.

But your computer takes another approach.

Laptops, smartphones and other devices depend on binary code. A mathematical language, binary dictates these high-tech gizmos. It tells your computer what the podcaster’s voice is like, what colors should appear in the YouTube video, and how many letters were used in the email your boss just sent.

you know Important things like this.



Binary code lives up to its name. Unlike the decimal system, it uses only two types of digits, which programmers call “bits”. Usually, there is “0” and there is “1”. and that’s all.

Today, we’ll show you how to convert a binary number to the more familiar decimal system. Then, like a good magician, we’ll do the exact opposite.

Don’t worry. With a little patience, you can master this “trick” – and have fun doing it!

know your exponent

Technically, 0 and 1 are the only bits you need to write a binary number. but that correct Among them, you have to understand the third value: 2.

It is best if we explain it through example. The number 138 is properly expressed in binary code.10001010,

How can your computer tell the vague meaning of this unambiguous string “138”?

Programming is part of the answer. Someone has informed your device that — in this case — the binary code indicates a number instead of a written word or sentence; There is a separate method for decoding the latter.

Once this basic fact is established, the code works by assigning a different exponent of 2 to each individual bit (ie, each 0 and each 1).

An exponent is a certain number of values ​​multiplied by itself. So, 2 to the third power, is written as 23 is 2 x 2 x 2, which equals 8.

Please enjoy the following Powers of 2 list. Trust us, you’ll want to see it soon.

20 = 1

21 = 2

22 = 4

23 = 8

24 = 16

25 = 32

26 = 64

27 = 128

28 = 256

29 = 512

210 = 1024

convert binary to decimal

Now we go back to our original binary number: 10001010

If English is your native language, take care of yourself. You are about to fight against your instincts. See, written English is read from left to right. But now, we have to break that binary number by going in the opposite direction: left to right.

In any binary number, the bit that is farthest to the right has to be multiplied by 20. Then the one to his immediate left is multiplied by 21.

Next, to do a little to its left is multiplied by 22. And so on and so forth.

Notice a pattern here? The personal exponent of 2 is being used in ascending order, from right to left,

OK, so now our job is to continue that pattern until we’ve matched the exponent of 2 – each one 0 and 1 – for each bit in the binary number.

We’ll stop once the last bit, which is the leftmost bit, has been multiplied by the appropriate exponent of 2.

A helpful way to keep your data straight is to physically line up the exponents on their corresponding binary bits on a sheet of paper. Ideally, it should look something like this:

good thing OK, now back to the actual conversion.

Because 10001010 has 8 different bits, we are going to do 8 different multiplication problems. Let’s start with 0 at the far right end.

What is 0 x 20? The correct answer is 0.

One problem down, seven to go. Move one place to the left. See “1” there? Well, 1 x 21 = 2. Now move one more space to the left. Doing this will give you 0 x 22, which is equal to 0.

If you continue to use this pattern, going from farthest right to farthest left, you’ll find:

0 x 20 = 0

1 x 21 = 2

0 x 22 = 0

1 x 23 = 8

0 x 24 = 0

0 x 25 = 0

0 x 26 = 0

1 x 27 = 128

Wait, we’re almost at the finish line!

Take the results of all those multiplication problems and add them together. not multiply, add, Knowledgeable?

What is 0 + 2 + 0 + 8 + 0 + 0 + 0 + 128 equal to?

Before we answer that, let’s get rid of all those zeros. We don’t need them in the additional problem. We really have to solve this riddle:

2 + 8 + 128 = ?

guess what? final answer is 138, Congratulations, we’ve come full circle! Get on a victory lap.

Note that 138 is a whole number. There is a technique to convert numbers with fractional components like 0.25 and 3.14 to binary. But full disclosure: It’s kind of complicated. If this doesn’t bother you and you want to learn more, the Institute of Electrical and Electronics Engineers (IEEE) has published a standardized conversion method.

Here’s a handy widget to help you with the conversions.

convert decimal to binary

After changing “10001010” to “138”, it’s time to reverse our process. Let’s say you started with 138 and had to convert it to binary. How would you do it?

Once again, the exponents are the key to the whole shebang.

Take another look at our “powers of 2” list. Find the value which is 138. comes closest to without crossing it,

A quick reread tells us that 138 sits between 256 (that’s 28) and 128 (that’s 27).

Now, we are going to subtract 128 from 138. Here is the equation:

138 – 128 = 10

Next, take that 10 and take the second gander in the exponentiation list. The power of 2 that comes closest to equaling 10 is 23 or 8. So at this point, our job is to subtract 8 from 10. As:

10 – 8 = 2

And what do you know? The number 2 is equal to 21.

This process gave us three significant figures: 128, 8 and 2. Our next objective is to connect them.

128 + 8 + 2 = 138.

Find a piece of paper if you haven’t already. Write down the value of each exponent of 2, starting with “128” (remember, this is 27) and “1” (which equals 20). Doing This is in descending order from left to right, And make sure to leave some space between each number.

Your scribbling should look like this:

128 64 32 16 8 4 2 1

As you can see, there are eight individual values ​​listed here. Draw a downward-pointing arrow (↓) below each value.

Then, consult the additional problem I wrote above, which says 128 + 8 + 2 = 138

Do you see “128” in that problem? If so, write “1” under the corresponding arrow. Is “64” written in the equation? Not! So under that arrow, we’re going to write “0”. Maintain the same pattern and you will get:

look familiar? We have 10001010 left—and as we’ve already established, this means “138.”

So there you went. Our cosmic magician has banished the rabbit and brought it back again. Carrots all around!

Source



Related News

Bing chatbot hotar och agerar hämndlystent

Chatboten från Microsoft Bingcalled Sydney har nyligen kritiserats för sitt ganska ovanliga och manipulerade beteende genom en teknik som kallas "injection

Oppos första hopfällbara telefon slår Samsungs Galaxy Flip där det gäller

Efter att ha utvecklat sin första hopfällbara smartphone 2021, hoppar Oppo in på nischmarknaden för hopfällbara clamshell. Under sitt globala lanseringsevenemang i

Vad är Sky Showtime, Netflix rival som kommer för att skaka grunden för streaming

Mitt i en våg av kontroverser med delade Netflix-konton på grund av de nya villkoren för de som vill dela ett konto, kommer SkyShowtime till