The magic formula for converting from one base to another

La formule magique pour la conversion d’une base à une autre

Converting numbers between bases consists of representing a number in a numeral system different from the one in which it was originally written. The most common numeral systems are base 10 (decimal), base 2 (binary), base 8 (octal), and base 16 (hexadecimal).

To convert a number from one base to another, it is necessary to understand the value of each digit in the original numeral system and represent it in the new base using the appropriate digits. This operation can be performed manually or with the help of a computer program.

Today we will see how we can convert a number from base a to base b.

Indeed, there are several ways to perform base conversions, and today we will focus on one that I find very interesting. It is a method that uses the following formula:(VWXYZ)b=(Z×b0+Y×b1+X×b2+W×b3+V×b4)10(VWXYZ)_b = (Z \times b^0 + Y \times b^1 + X \times b^2 + W \times b^3 + V \times b^4)_{10}

Here VWXYZ are digits belonging to ℕ (the set of natural numbers) and b is the base. To convert to base 10, you simply perform the calculation as shown in the formula. Let us see how the calculation works when converting to other bases using this formula.

Converting from base b to base 10 (decimal)

Using the formula(VWXYZ)b=(Z×b0+Y×b1+X×b2+W×b3+V×b4)10(VWXYZ)_b = (Z \times b^0 + Y \times b^1 + X \times b^2 + W \times b^3 + V \times b^4)_{10}

to convert from base b to base 10, you simply perform the operation as shown. Converting to base 10 is very straightforward. In fact, base 10 acts somewhat like a central hub for converting from one base to another—for example from base 16 to base 8, 3, or 2.

Example(1F)16=(15×160+1×161)10=(31)10(1F)_{16} = (15 \times 16^0 + 1 \times 16^1)_{10} = (31)_{10}

  • Converting from base b to base 16 (hexadecimal)

To go from base b to base 16, the easiest method is to go from b to 10, and then take the number we find and divide it by base b.

Example: converting (72)8 to base 16 using our formula.

SOLUTION:
(72)8 = (2*8^0 + 7*8^1)10 = (58)10. Then we divide 58 by 16.

58 = 3*16 + 10 = (3A)16, so we have (72)8 = (2*8^0 + 7*8^1)10 = (58)10 = (3A)16.

  • Converting from base b to base 2 (binary)

To perform the conversion from base b to base 2, one of the easiest methods is to perform the operations we just did above for the hexadecimal base. First, we convert from base b to base 10; of course, if we are already in base 10, there’s no need to convert. Once we are in base 10, to get to base 2 we simply divide by 2 until we obtain a result less than 2, that is, 1.

conversion-binaire-e1550588947109 The magic formula for converting from one base to another

Example: (FF)16 = (255)10, and by dividing 255 by 2 several times we get 1111 1111.

(FF)16 = (255)10 = (11111111)2

Converting from base b to base 8 (octal)

In this last case, we will go from base b to base 2 using the method explained above and then we just interpret the obtained binary digits by segmenting the sequence of digits into blocks of 3 digits.

Examples: (AFEC)16 = (45036)10 = (1010111111101100)2 then we segment the obtained result into blocks of 3, 3 digits starting from the right to the left like this: 001 | 010 | 111 | 111 | 101 | 100. In the case where the last block does not reach 3 digits, you can fill in with 00 as I did. After havingSegmented, the interpretation is easy. Indeed,

100=4;
101=5; (111)2=(7)7; (111)2=(7)7;
(010)2=(2)7; (001)2=(1)7;

Which gives us (AFEC)16=(45036)10=(1010111111101100)2=(127754)7

We have just seen how to easily and surely convert our numbers from one base b to another base. We took the example of common bases, but you can use the same principle to convert to other bases. And that was all for this little calculation tip, good luck with your studies, and we will see each other very soon.

Share this content:

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Rating

eighteen − 18 =

Vous avez certainement manqué...