The elementary mathematics of binary-decimal converters
If you google "How to convert from decimal to binary," you'll find four easy algorithms, two for the integer and two for fractions. In the first section of this article, we provide some examples of each. Even though it's usually sufficient to merely be familiar with the algorithms, I've made it a goal to learn how and why they function. Section 2 of this article delves into the elementary mathematics behind each of these. If you ever find yourself forgetting an algorithm, knowing this might help you recall it. You should get a notepad and a pen and follow along with the calculations as I do them to help you remember the material. You can find examples of each of the four algorithms below on the internet.
The first step in converting an integer to binary is to divide it by 2 while keeping track of the quotient and the remainder. Repeat dividing by 2 until the quotient becomes zero. The remainders can then be written in descending order.
Take the number 12 as an illustration of such a transformation.
We'll start by dividing the number in half and writing down the quotient and remainder.
The rest can be written in reverse order (1100) now. Therefore, in binary, the number 12 corresponds to 1100 in the decimal system.
Multiply the fraction by 2, keeping track of the integer and fractional part, and you'll have a binary representation for the fraction. Keep multiplying by two until the resulting fraction is zero. Then, simply record the integer factors resulting from each multiplication.
See the fraction 0 as an example of a number that can be converted to decimal form below. 375
Let's just output the resulting integer fraction at each iteration, which is 0 in this case. 011 So, 0 There is no digit for 375 in the decimal system. This is the binary representation of the number 11.The only fractions that can be represented exactly in binary form have denominators that are powers of two. Examples of this include denominators of zero and similar. 1 (1 / 10) and 0 Binary representations are limited to powers of two, but 2 and 15 are not powers of two. Mantissa bits must be rounded down to fit into the IEEE-754 floating point representation, which is 10 bits for half-precision, 23 bits for single-precision, and 52 bits for double-precision. Floating-point approximations of 0 vary in accuracy from one implementation to the next. 1 and 0 Numbers written in decimal form can be close to 2, but never exactly 2. That's why you'll never be at a loss for words and never reach zero. 1 0 2 == 0 3
Begin with the left when performing a left-to-right conversion of binary integers to decimal. Multiply the number you're adding to by two, and add the number you're adding. Keep going until no more digits remain. The fraction 1011 is used here to illustrate a similar conversion.
When converting a binary fraction to a decimal form, zero is the starting point. To get the next digit, add the current one, and divide by 2; apply this to your current total. Keep going until there are no more digits An illustration of such a transformation using the fraction 0 is provided below. 1011 To do this, I've simply substituted multiplication by 1/2 for division by 2.
You can now convert binary numbers to and from decimal with the help of these four straightforward algorithms.
The key to comprehending the efficacy of those algorithms lies in the number's expansion in base q. An integer in any numeral system looks like this:
- The value of N is a whole number.
- The x represents the digit (0–9 in the base–10 system; 0–1 in the base–2 system).
- It all starts with q, where 10 in our case is the base value for our system and 2 is the base value for our base-2 system.
Base q expansion of the number N, or just base q expansion, will be used throughout this article. First, let's compare the binary and decimal representations of the number 12.
Similarly, any fractional number can be written as follows, regardless of the system used.
- N is a decimal number
- The x represents the digit (0–9 in the base–10 system; 0–1 in the base–2 system).
- In a base-10 system, q is 10, and in a base-2 system, q is 2.
Referring to the digit zero 375 is written as follows in both the binary and decimal systems.
A surprising application of this base-q expansion form is the conversion of a decimal number to binary. We can do the same thing for the number 12: Before delving into the binary representation, let's pretend we have no idea and write it out with xs in place of the unknown digits.
It is our job to track down every x. So, let's see what we can do. All summands, with the exception of the last, are multiples of two, so they are all even numbers. Based on this, we can determine the value of x0: if the input integer is even, then x0 is 0, and if it is odd, then x0 is 1. Since 12 is an even number, x0 here is also zero. Yes, let's put this down on paper:
The x1 value must be determined next. Factoring out 2 allows us to isolate x1, as all summands from x1 to xN are multiples of 2. In that case, let's:
It is also evident that the total of the values contained within the brackets is 6. As a result, the first actionable item is:
To continue determining the missing x's, please. We can express the polynomial within the brackets as a standalone statement:
The same reasoning used up above allows us to confirm that x1 = 0. Let’s rewrite it and take 2 into account once more:
Then, the second step is:
There is a pattern emerging now. After the initial factorization, we can keep factoring 2 until the quotient becomes 0. Okay, so let's keep this pattern going and see what happens.
Given that the quotient is 1, we now have only one remaining summand and can rewrite the expression as:
That brings us to our third and final step:
The resulting scenario is as follows:
There is no doubt that x3 = 1. However, since a quotient is required by our algorithm, let's rewrite the previous expression as follows:
When we divide by zero, we're left with nothing and have completed the process. How about we put it in writing?
Therefore, the process of conversion is complete. We've laid out the stages of our transformation below:
It is now obvious that the value of the remainder at each step is equivalent to the value of the x at the corresponding position. According to the aforementioned algorithm, the binary representation of the number 12 is 1100.
It's important to recall that our original goal was to demonstrate the efficacy of the algorithm involving a "diving by 2" Follow the above procedure and shift the 2 to the left side of the expressions:
Here you can see the logical progression that led to the algorithm described in the introduction. The numbers for all four procedures can be represented in this way, as well.
If you want to learn about the algorithm for converting binary to decimal, you'll need to know how we arrive at that representation.
I'll also use the base-q expansion form of fractions to demonstrate why we multiply by 2 and take the integer part when translating between the two systems. As a decimal fraction, I'll use 0. the first 375 words of the article In the same vein as the integer portion, let's pretend we don't know the binary representation of this number and write it out with xs standing in for the unknown digits:
The goal, as with integers, is to identify every instance of x. So, let's figure out a way to make that happen. The first thing to note is that when we divide by a negative power of 2, we get a fraction where the denominator is 2. Change the above phrase into the following:
The solution is as obvious as factoring out 1/2 in the appropriate part of the expression. Sure, let's do that:
Half a step to the left, and we're good to go!
We now have a single variable, x1, which can take on the values 1 or 0. What digit it has can be found by examining the remaining summands:
Consider how large this set of numbers can potentially become. Simply replace all x's with 1's to get the final sum if the greatest possible value for x is 1.
Since the sum of a geometric series of fractions is constrained to fall within the interval [0, sum], the greatest number that such a sum can yield is 1. Let's take another look at our idiom:
It should be obvious that if the right side is less than 1, then x1 can't be equal to 1, and so it's equal to 0. The rest of the expression is also equal to 0. 75
This matches the initial description of the algorithm perfectly:
First, let's decimalize 0 to make it more manageable. 75.5, then subtract 1/2 to get x2 all by itself:
as well as shift 1/2 to the left:
The left side of the expression cannot be greater than 1 if x2 is zero, but it is one. 5.x2 = 1, leaving the rest to be 0. 5 So, to put it in writing:
And this, once again, conforms to the scheme introduced at the outset:
For the remainder of the value of zero, let's proceed in the same manner. 5
The same reasoning as before reveals that x3 = 1 and leaves no remainder in the fraction:
Final step looks like this since the remaining fractional part is 0.
So, let's re-write the entire procedure:
My original algorithm is exactly like this. The computations for all three steps can be represented in a single form, just as we did with integers:
Once again, a thorough understanding of this representation is crucial, as we will be using it to investigate binary to decimal conversion.
Many programmers are surprised to learn that some fractions that can be represented finitely in the decimal system cannot be represented finitely in binary. It is this misunderstanding, however, that underlies the seemingly strange result obtained by adding zeros. 1 to 0 2 What then is it about a fraction that decides whether or not it can be represented by a finite number system? It's a lot of work If you want to keep things simple, just remember that the denominator of a fraction should be a power of the system base for any number to be represented finitely. In order to represent zero exactly in the base-10 system, the denominator must be a power of 10. In decimal form, the number 625 reads as follows:
and cannot be represented exactly as 1/3:
The same applies to base-2 numbers:
However, if we rule out the number 0, 1 because 10 is not a power of 2 and therefore 0 is the answer. Within the framework of the binary system, 1 will represent an infinite fraction. Applying the above-mentioned algorithm, let's take a look:
This process can be repeated indefinitely, but for the sake of clarity, let's express it as a continued fraction.
In order to demonstrate why the algorithm of multiplying by 2 is effective, I will once again use the binary integer 1011. The number will be written in its base-q expansion form here as well. Let's put it in this form for easy reference:
Due to the fact that all summands are divisible by 2, we can factor out 2 until the quotient becomes 0. Come on, let's do it:
Now, if you just use the order of operations in math, you'll get the same results I showed at the outset, including:
The binary representation of the number 11 is 1011.
Finally, we've reached the end of the algorithms! You've probably figured out the workings of it on your own by now. If that's not the case, then let's examine the logic behind its success. The key is again the expanded form of the number in base q. To start, let's pretend that 0 is our starting point. 1011, from the introduction Let’s put it in its full form:
Since every summand is a power of 2, we can continue to remove 1/2 as a factor until there is no longer any fractional component. Yes, let's do that.
The initialized algorithm is the result of performing the mathematical operations in the specified order:
This way, 0 The binary representation of the number 1011 is 0. That's the decimal equivalent of "6875"
Numerous individuals possess a Wii console but are unable to use it due to improper cables or incompatibility with their TV or monitor. However, you can effortlessly connect a Wii console to any TV utilizing an adapter since all modern TVs and monitors support HDMI connections. Thus, we have
Do you remember how the Nintendo Wii revolutionized gaming? Its motion controls were a game-changer and the available games, such as Wii Sports, were amazing. But as technology progressed, the Wii became outdated, and playing it nowadays is challenging because of video output compatibility
The Convert Time Stamps feature can be employed to transform the format of time stamps. A range of conversions are supported, including GPS seconds-of-week to GPS standard time, GPS time to GPS standard time, GPS seconds-of-day to GPS seconds-of-week, Unix time to GPS standard time, UTC seconds-of-day
Unleash the potential of that neglected gift card by transferring its value to your PayPal account! Not only will you bolster your balance, but you’ll open up a world of spending opportunities. But how does one go about making this shift? Let’s dive into the basics so you can make the move with