Number Base Converter
This tool will let help you convert numbers from one base to another, for example decimal to binary.
A base (also referred to as the radix) number is the number of unique digits used to represent a number. In the base 10 system (what we will refer to as the ‘anchor’ base!), we represent all numbers using digits 0-9. We also think of numbers that we see as groups of 10’s. For example, the number 321 (which can also be denoted as (321)10 to iasize that it is in base 10) has a single count of 1, two counts of 10’s, and 3 counts of 100’s (100 in itself being 10 counts of 10!). While this seems very obvious, it is usually agreed upon that there is not necessarily any strong reason why we should group numbers by 10’s. In fact, it seems that the biggest reason why we have agreed to use base 10 as the ‘anchor’ is because it corresponds to us counting on our fingers!
Consider the same example, 321, in base 5. Base 5 would be a number system in which the used digits are 0-4 and in which we count in groups of 5’s. Thus , we would represent the number as (321)5 and understand it to be a single count of 1, two counts of 5’s, and 3 counts of 25’s (25 in itself being 5 counts of 5’s!). We can add those counts 1 + 5 + 5 + 25 + 25 + 25 to get the equivelent number in base 10, 86. This can be extended to create a general algorithm for understanding any numbering system.
By convention, we use the letters a-z to represent the digits 11-35 respectively . For example, ‘c’ would represent a count of 13. However, try to think as a-z as symbols just like 0-9 which could stand for anything. If in a different world the ‘anchor’ system would have been base 12, for example, it is easy to imagine that we would have added symbols outside of the alphabet to represent the counts of 11 and 12.
Why should we care about different numbering systems? For one, it helps us think of what numbers are in a better way. We often implicitly think of time to be in base 60 as we count seconds and minutes in those groups. If we want to make an application that relies on timing, it could be very helpful to use to have a solid grasp of how a base 60 system ‘works’ and what implications it has for simple arithmetic.
More importantly, however, in computing we use the base 2 system, also referred to as the binary system, in order to represent all the information that a computer holds. After all, a computer (very simplistically) can be seen as many switches that are either on or off, so representing on or off as 1 or 0 comes naturally. Well, naturally to the computer, but for most humans seeing the number (1001)2 does not make much sense, and even people very aware of how the binary number system works may have to convert to base 10 in order to understand what the number represents. However, with a holistic approach to number systems, we can find better ways to view and understand the binary system that govern how every computer works.
In the examples section, we use the base systems, 2, 8, and 16 and show why these number systems naturally work together and why they are all so commonly used in computing.
The general algorithm for getting a number from base X to base Y is to first convert is to first convert base X to base 10 using a division table and then convert from base 10 to base Y using simple multiplication and addition. It is important to note that translating into base 10 is simply for convenience purposes; doing arithmetic operations in our ‘anchor’ base is much simpler for us. Example 4 shows an alternative conversion that does not rely on converting to base 10 first and which is commonly used in computing.
Example 1
Let’s say we want to convert the number 123 to base 16. To do so, since 258 is in base 10, we can construct a table where we will continuously divide 258 by 16 (the base we want to convert to), keep track of the quotient and remainder, and stop dividing once the quotient equals 0. The table would looks as following:
Division | Quotient | Remainder | Digit placement |
---|---|---|---|
258/16 | 16 | 2 | 0 |
16/16 | 1 | 0 | 1 |
1/16 | 0 | 1 | 2 |
Now we can note the remainder and the digit placement columns to easily come up with the new number. If we use the digit placement system …210 and replace the value in each position with the remainder we get 102. Thus, (258)10 = (102)16.
Example 2
Let’s say that we now want to convert (102)16 to base 10. We can expect the answer to be 258 because of Example 1, but how do we get there ? Remember, bases are all about grouping counts. Earlier, we described a number such as (102)16 to be 2 single counts, 0 counts of 16’s, and 1 count of 256 (which is 16 counts of 16’s). This idea can be expressed numerically as:
(1 x 162) + (0 x 161) + 2
When we calculate this we get 258, our answer! Note that for generalization purposes we will often really write the last number as being multiplied by the base to the power of 0, which really just is 1:
(1 x 162) + (0 x 161) + (2 x 160)
Example 3
Let’s say we want to convert (102)16 to base 2 (binary). Remember that our general algorithm says that we need to get from the first base to base 10 and then from base 10 to the end base. We have already done in Example 2the translation of (102)16 to base 10, so our first step is already done!
Our second step is to get from our answer, 258, to base 2, which once again requires a table. The table will be as following:
Division | Quotient | Remainder | Digit placement |
---|---|---|---|
258/2 | 129 | 0 | 0 |
129/2 | 64 | 1 | 1 |
64/2 | 32 | 0 | 2 |
32/2 | 16 | 0 | 3 |
16/2 | 8 | 0 | 4 |
8/2 | 4 | 0 | 5 |
4/2 | 2 | 0 | 6 |
2/2 | 1 | 0 | 7 |
1/2 | 0 | 1 | 8 |
Thus, using the table we get our answer, (100000010)2.
Example 4
Remember that our algorithm is for convenience and that if there is a more convenient algorithm to convert from a specific base to another, that can be very useful. We do know that there is a very simple way to convert from base 16 to base 2 and back.
We start by considering each digit in base 16 as represented as the equivalent 4 digits in base 2. For example, (2)16 = (10)2, so we can represent 2 in base 16 as 0010 in base 10. We build onto this for all digits. Recall that a-z are used to denote digits greater than 9, so for example ‘c’ denotes a count of 12. (12)16 = (1100)2, so those digits correspond. If we want to convert from base 16 to base 2, we can simply replace each digit by the corresponding base 2 digits.
For example, if we take each digit in (102)16, we can get 1 = 0001 , 0 = 0000, 2 = 0010. Just connect these to get (000100000010)2, which you can notice is the same answer we got in Example 3! The trailing 0’s are of course, as in base 10 system, not counted.
Likewise, to convert from base 2 to base 16 we simply can group every 4 digits and replace them with the base 16 representation. If we have (100000010)2, we group (0001)(0000)(0010) and convert each grouping to base 16 to get (102 )16! Note that we added trailing zeros to ensure that each grouping is of four digits.