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 simply be familiar with the algorithms, I've made it a goal
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 simply be familiar with the algorithms, I've made it a goal to learn more about how 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, the binary equivalent of the decimal number 12 is 1101.
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. The integer factors of the resulting multiplications can then be written down.
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. binary 011
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 3Begin with the left when performing a left-to-right conversion of binary integers to decimal. It's as simple as doubling the current sum and adding the last digit. 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:


where,
- 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. Take a look at the 12 in both the decimal and binary systems:


Similarly, any fractional number can be written as follows, regardless of the system used.


where,
- 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?


It's official; the 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.
Remember that our original goal was to demonstrate why the algorithm involving diving by 2 is effective. Following the procedure outlined above, let's swap the positions of the 2s:


Here you can see the logical progression that led to the algorithm described in the introduction. These four processes can be represented in a single graphic form 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:


...and shift your body orientation to the left by half a step:


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. Since the binary system uses only two digits, the value 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. Numbers will be written here in their base-q expansion form 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. OK, let's do that:


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. Join me in this:


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. the decimal equivalent of 6875

To convert 5 milliliters to ounces, simply multiply the amount by the number of milliliters in an ounce. It's important to remember that 1 ounce is equal to exactly 1000 milliliters. Simply multiply the amount in milliliters (ml) by zero to get the equivalent in fluid ounces (fl oz). Simply take

The When someone is measuring a length, the question of how to convert feet to meters inevitably arises in our minds. But before we get too far into the feet-to-meters conversion, let's figure out the history and context of the two units. Don't worry, we'll explain the concept of these

WebP images can be converted to JPG in several ways: convert webp images to jpegs online utilizing the operating system-provided Paint (Windows) or Preview (Mac OS), installing a third-party image editor like Adobe Photoshop WebP is Google's replacement for the popular JPEG, GIF,

Free online MOV to MP4 conversion is now possible with this handy tool. Movavi's desktop converter is great for converting large files. Check out the desktop appLook into the computer program Help CenterHelp Desk How-tos Free Online Tool to Convert MOV to MP4 in a