FB pixel

Number Systems & Base Conversions | Digital Logic 1.1New

Published


Welcome to our first lesson on Digital Logic, where we’ll cover some fundamentals required before studying the core concepts of the subject. In this initial lesson, we’ll start by explaining what a number system is, which are the commonly used number systems, and we’ll also look at how to perform conversions between them. With that stated, let’s begin our journey in digital logic!

What is a Number System?

Number systems, or numeral systems, are basically a predefined set of symbols used to represent numbers in a consistent manner. They help us count things, perform arithmetic operations, and convey information accurately.

Figure 1: Systems of Numeration
Figure 1: Systems of Numeration

There are hundreds, if not thousands, of number systems worldwide, considering all the languages, cultures, and specific applications. However, in this lesson, we will focus strictly on the number of systems used in computing, that is - Binary, Octal, Hexadecimal, and also their relationship with the familiar Decimal system.

Why do we need different Number Systems?

The reason is their application in different real-world scenarios. For example, binary is used in computer programming, hexadecimal is used in web design for color codes, and decimal is used in everyday arithmetic. Another important reason for introducing a variety of number systems was to make it easier for human interpretation. Reading through hundreds of lines of 0’s and 1’s wouldn’t be fun at all!

Since our childhood, we’ve been using the decimal number system to do basic arithmetic. Look at the number below. How would you read that?

Of course, that is “Eight thousand two hundred and thirty-seven”. But how did we come to that conclusion? To understand that, let’s break it apart. The number 8237 can be written as

If we separate the multiples of 10 and the digits, we get

Now, let’s change the 1000, 100, 10, and 1 into powers of 10, which will be as follows.

You can observe that every digit of our original number occupies a weight to it, in the form of powers of ten. The reason why we did this will make much more sense as we proceed further in the lesson.

Consider another example, this time with a decimal point. To represent the weights of the digits on the right side of the decimal point, we’ll be using negative powers of 10.

In our example, we started from the rightmost digit and multiplied them with a power of ten based on its position and then added them all together. This expansion is called the positional notation and is essential for understanding how numbers are represented and manipulated in different number systems.

If you take into consideration the decimal point, notice how it is used to separate the positive and negative powers of 10. The digits on the left of the decimal point in our original number (219.52) are referred to as the integer part of the number, and the numbers on the right of the decimal point are called the fractional part of the number.

The decimal numeral system is also called the base-10 or radix-10 system, because we can use ten symbols, i.e., 0,1,2,3,4,5,6,7,8 and 9, to form any number we want. In our example above, in order to be explicit that we are using a decimal or base-10 number system, we should add a subscript 10 to the number.

That’s a complete representation of the number. Let's generalize a few concepts and definitions before jumping on to the other number systems.

General Representation of Any Number

Figure 2: Representation of a number
Figure 2: Representation of a number
  • Base or Radix: It represents how many different symbols can be combined to form a number.

    It is crucial to note that the maximum valued symbol in any number system is always one less than the base of that number system, due to the number 0 being included in all number systems. For example, base-10 numbers have the maximum valued symbol as 9. Similarly, let’s say we used a base-6 number system. Then, the maximum valued symbol would be 5. This can be generalized as

Maximum valued symbol of base N = N - 1

Did you know that Radix is a Latin word for "root"? In arithmetic, "root" can also be thought of as another word for "base".

  • Radix Point: It is used to separate the integer and fractional part of a number. In another sense, it separates the negative and positive powers of the radix.
  • Most Significant Digit: The digit present on the extreme left of the number, i.e., d4 in our case.
  • Least Significant Digit: The digit present on the extreme right of the number, i.e., d-3 in our case.

NOTE: When dealing with binary numbers, we’ll often refer to them as MSB (Most Significant Bit) and LSB (Least Significant Bit).

Using the general expression, you can have as many numeral systems as you want, but our focus in this lesson would be to cover the most commonly used ones - Binary, Octal, Hexadecimal, and their relationship with the familiar Decimal system.

Binary Number System

The binary number system serves as the foundation of digital logic. Everything revolves around the concept of 0 and 1. This is the reason why Binary is called the base 2 number system, as we’ve got only two symbols to represent any binary number.

Examples: (10111)2 , (110)2 and (110010.101)2

Octal Number System

Another popular number system is the Octal. They are called base 8 numbers, which, based on our definition above, means that we can use only up to 8 different symbols to form a number, i.e., 0,1,2,3,4,5,6 and 7.

Examples: (27)8 , (374.51)8 and (102.77)8

Notice how “8” is not used in any of the examples above. The maximum valued symbol is 7. This is a fundamental rule to be followed in any number system.

Hexadecimal Number System

Hexadecimal numbers are called base 16 numbers, meaning that we can use 16 symbols. But we are aware of only ten digits or symbols to form a number, i.e., 0 to 9. We need six additional symbols, and for that, we use the letters A, B, C, D, E, and F, and those letters actually represent the decimal numbers from 10 to 15!

Figure 3: Decimal equivalents of Hexadecimal numbers
Figure 3: Decimal equivalents of Hexadecimal numbers

The only reason why we use letters from the alphabet as placeholders for decimal numbers is to avoid any confusion while interpreting them. If we didn’t do that, there would be no way for us to figure out if the number “12” in (34124)16 represents “1” and “2” separately or “12” as a single entity.

So, any hexadecimal number can be formed using 0,1,2,3,4,5,6,7,8,9, A, B, C, D, E, and F. However, we replace the letters with their equivalent decimal number while performing the conversion.

Examples: (13F)16 , (EF2)16 , (64A.3F)16

There was also the Roman number system, or Roman Numerals, that you are likely familiar with, but we don’t really use it for computers or in digital logic. If you are interested in knowing why, find the reason here: Systems of Numeration.

Now that we are aware of the commonly used number systems, let’s understand how to perform conversions between them.

Conversion between Bases

CircuitBread provides several tools, one of which is the Base Converter. We can always use the available calculators, but knowing a quick method comes in handy! That’s why, in this section, we’ll take a look at some of the commonly used conversions that can save you some time and effort. Let’s go over them one by one.

Any Number System to Decimal

Example 1: Convert the binary number (10111)2 to its decimal equivalent.

Solution: We are given a binary number, which is base 2. So, let’s start by writing the powers of 2 on top of the given number based on its position in the digit.

Calculate the values of those powers, and then multiply them with the digit exactly below them.

Finally, add all of them together,

And that’s it! That is the decimal equivalent of the given number. We can use the CircuitBread base converter to verify our result.

Figure 4: Binary to Decimal Example 1
Figure 4: Binary to Decimal Example 1

Example 2: Convert the binary number (1011.11)2 to its decimal equivalent.

Solution: In the given question, we also have a radix point. So, we’ll have to use negative powers of 2 for the fractional part, and then use the same process as shown in the example above.

Let us again verify our result:

Figure 5: Binary to Decimal Example 2
Figure 5: Binary to Decimal Example 2

If you look carefully, you'll see that we are actually following positional notation to solve these! The method we showed above is just a less overwhelming version of it. If you want to perform the conversion by expanding in positional notation, here's what it looks like:

You can use either of the above two methods to convert any number system to its decimal equivalent. Consider the following examples, where we will convert octal and hexadecimal numbers to decimal.

Example 3: Convert the octal number (15.2)8 to its decimal equivalent.

Solution: As it is a base-8 number, we’ll write the powers of 8 on top of the digits, and then follow the same procedure as we did previously.

Figure 6: Octal to Decimal Example
Figure 6: Octal to Decimal Example

Example 4: Convert the Hexadecimal number (D5A.C)16 to its decimal equivalent.

Solution: You know what we need to do! Let’s multiply the digits with the powers of 16 this time. But we also need to replace the hexadecimal characters with their decimal equivalents, i.e., D = 13, A = 10 and C = 12.

Figure 7: Hexadecimal to Decimal Example
Figure 7: Hexadecimal to Decimal Example

In summary, to convert any base number to decimal, we simply need to expand the given number in the positional notation, solve the multiplications and additions, and you’ll have the decimal equivalent.

Special Example 1: Convert the binary number (10110)2 to its decimal equivalent.

Solution: To convert this into decimal, we’ll use a different method this time. We start with a weight of 1 for the LSB (rightmost digit) and double it for every next digit.

Now, discard the weights which have a “0” below them. So we get

Finally, add the remaining weights, and that’s the decimal equivalent we were looking for.

Figure 8: Binary to Decimal Example (Method 2)
Figure 8: Binary to Decimal Example (Method 2)

This method is simple and extremely useful when we want to convert a binary number quickly into hexadecimal, as we’ll see later.

Decimal to Binary

For this conversion, we’ll use the divide-by-base technique, where “base” indicates the number system we aim to convert into, which is “2” when dealing with binary. Let’s look at an example below:

Example 5: Convert the decimal number (54)10 to its binary equivalent.

Solution: Begin by dividing the number by 2 and note the quotient and remainder in separate columns:

Once you have the quotient of the first division, that quotient becomes the dividend in the next step. Again, perform the division, and note the quotient and remainder.

This process is repeated until we are left with 1 as the dividend in the last step.

Now the information in the remainder column is actually the binary equivalent we were looking for! But here’s the catch, the correct sequence for the binary equivalent is obtained when going from bottom to top in the remainder column, and not the other way around.

So, we get,

(110110)2

This was a bit tricky. We’ll verify our answer to be sure:

Figure 9: Decimal to Binary Example 1
Figure 9: Decimal to Binary Example 1

Example 6: Convert the decimal number (8.375)10 to its binary equivalent.

Solution: This time, we also have a fractional part in our number. In this case, we need to separate the integer and fractional parts and calculate their binary equivalents by different methods. Let’s start with the integer part and follow the same divide-by-base method as in the previous example:

Coming to the fractional part now, we will use the multiply-by-base method. We’ll write the fractional part, 0.375, and multiply it with our base, 2, which gives us 0.75. Now, we are interested in the integer part of this result, which is 0 in this case. Let’s note it down separately.

Once done, we consider the fractional part of 0.75, that is 0.75, and multiply it by 2 again, which gives us 1.5. Again, consider the integer part of this result, which is 1.

Note it down and perform the same steps one more time.

Now we get 0 in the fractional part of the resultant and there’s no further calculation required. For the fractional part’s binary equivalent, note down the results from top-to-bottom, which is the opposite of what we did for the integer part’s binary equivalent.

Okay, so if we write the binary equivalents of the integer and fractional parts together, we get

(1000.011)2

We’ll also verify our result

Figure 10: Decimal to Binary Example 2
Figure 10: Decimal to Binary Example 2

Before moving on to the next section, let’s take a look at another method to convert decimal numbers into binary, which gets us to the answer quickly.

Special Example 2: Convert the decimal number (75)10 to its binary equivalent.

Solution: If you remember the special example we discussed in the previous section, we made use of the fact that the weights for binary numbers double with every digit. Let’s use that again.

We start with writing the weights and we’ll stop when the weight becomes equal to or greater than the number we want to convert. So in this case, we start with 1, 2, 4 and go up to 128, as 128 is the next highest weight after our number 75.

Now consider the weight equal to or just smaller than the number we want to convert, which in this case is 64. Assign a “1” below it, and then find the difference between 75 and 64.

The next step is to find the weight that is equal to or lesser than 11, which is “8”. So this time, assign a 1 below “8”, skipping 32 and 16, and again find the difference, which gives us 3.

The next 1 should be assigned below the weight 2, and finally another 1 in the end.

Now, write a “0” below all the other weights

And that’s it! You have the binary for 75 as:

(1001011)2

Figure 11: Decimal to Binary (Method 2)
Figure 11: Decimal to Binary (Method 2)

Wasn’t this much more intuitive than dealing with all those divisions? With practice, this will become second nature to you and prove out to be immensely helpful for what we are about to discuss in the next few sections.

Decimal to Any Other Base

We follow the exact same method if we want to convert the decimal number into a base other than binary, let’s say base-8. In that case, we divide by 8 for the integer part and multiply by 8 for the fractional part. Try converting the example above and see if you get your answer as (23.5)8. We’ll include a couple more examples for you to practice in the quiz section of our blog. Check them out to test your understanding.

Binary to Hexadecimal & Octal

In order to convert binary numbers to Hexadecimal or Octal, we use the method of grouping the binary digits.

For hexadecimal, we group four binary digits because 24 = 16. For octal, we group three binary digits because 23 = 8. If you’d like to know more about why that works, find it here: Octal and Hexadecimal Numeration

Example 7: Convert the binary number (110101101110)2 to its hexadecimal equivalent.

Solution: Starting from the Least Significant Bit (LSB), or the digit in the far right, we’ll start making groups of four binary digits. Remember, you should always begin this process from the LSB and not the other way around!

Now, let’s replace these grouped binary values with their decimal equivalents. Converting them should be fairly easy if you remember the shorter method discussed in the special example 1 above. Using that, we get:

Once you’ve reached this step, the only thing left to do is to replace the decimal values with their hexadecimal placeholders and combine them.

That’s it! We’ll verify our answer by using the CircuitBread conversion tool, and yes, that does give us the same result.

Figure 12: Binary to Hexadecimal Example 1
Figure 12: Binary to Hexadecimal Example 1

Example 8: Convert the binary number (1100101011.110)2 to its hexadecimal equivalent.

Solution: This time we also have a radix point, or binary point, to be taken care of. The binary point divides the number into the integer part and the fractional part, as we studied above. This changes the rules a little bit.

To make groups for the integer part of the number, we start from the digit on the left of the radix point and move leftwards, making groups of four digits, as we already know.

But for the fractional part of the number, we start from the digit on the right of the radix point and move rightwards, as indicated below

As you can see, we clearly don’t have four binary digits for the groups on the two sides. To solve this problem, we’ll perform zero-padding, or simply stated, we’ll add additional zeroes to make groups of four without changing the overall value of the number.

Now, we’ll again follow the same procedure of replacing the groups with their decimal equivalents, using the quick method in the special example 1, and finally, those decimal numbers with their hexadecimal equivalents.

There you have it. We’ll once again perform a sanity check using our calculator, which gives us the same result, as you can see below.

Figure 13: Binary to Hexadecimal Example 2
Figure 13: Binary to Hexadecimal Example 2

That’s it for the binary to hexadecimal conversion. For binary to octal conversion, there’s only a single change required. Instead of making groups of four, we make groups of three binary digits, and all the remaining steps are exactly similar to what you just read. We encourage you to go back to the examples above and try converting the same binary digits to their octal equivalents. See if you can match the octal equivalents shown in the calculator snapshots!

Now, let’s understand how to convert an octal/hexadecimal number back to its binary form. This time, let’s consider an octal number.

Octal & Hexadecimal to Binary

Example 9: Convert the octal number (274.13)8 to its binary equivalent.

Solution: To perform this conversion, we follow the reverse procedure of what we did in the previous section. We start by splitting the given number

Because it is an octal number, we’ll write down their binary equivalents using only three digits and following the method showed in special example 2.

Now, if you group these again, that’s your binary equivalent.

Figure 14: Octal to Binary
Figure 14: Octal to Binary

Example 10: Convert the hexadecimal number (F7D.2)16 to its binary equivalent.

Solution: We’ll split the digits and replace the hexadecimal symbols with their decimal equivalents. Then, we’ll replace them with their binary equivalents, but this time using four binary digits, as we are dealing with a hexadecimal number, not an octal.

(111101111101.001)2

Figure 15: Hexadecimal to Binary
Figure 15: Hexadecimal to Binary

Well, that was all we wanted to tackle in this lesson. We can perform several other conversions, but they are all time-consuming, and it is much better to do them using calculators. We encourage you to take the quiz and see if you can perform these conversions yourself. If you have any questions, let us know in the comments below.

Another fundamental topic to tackle before we dive into the more exciting topics, is the concept of complements. Complements help us represent negative numbers in a machine-friendly way, and they also simplify arithmetic operations between numbers. So in our next lesson, we’ll learn how to find the complement of a number and how to take advantage of them to simplify calculations.

Graduation Cap

Check Yourself

10 Questions

Make Bread with our CircuitBread Toaster!

Get the latest tools and tutorials, fresh from the toaster.

What are you looking for?