Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
Number System
2.1.
Decimal Number System
2.2.
Binary Number System
2.3.
Octal Number System
2.4.
Hexadecimal Number System
3.
Number System Relationship
4.
Base Conversions
4.1.
Decimal to Binary
4.2.
Binary to Decimal
4.3.
Decimal to Octal
4.4.
Octal to Decimal
4.5.
Hexadecimal to Binary
4.6.
Binary to Hexadecimal
5.
ASCII
6.
FAQs
7.
Key Takeaways
Last Updated: Mar 27, 2024

Different Number Systems and their Interconversion

Author Abhay Trivedi
0 upvote
Master Python: Predicting weather forecasts
Speaker
Ashwin Goyal
Product Manager @

Introduction

The Number system is a technique to represent and work with numbers. The decimal is the most common number system among other popular number systems like binary, octal, hexadecimal, etc.

Recommended Topic, Microinstruction in Computer Architecture and Difference Between Jfet and Mosfet

Number System

Digital and Electronic systems may use various number systems like Decimal, Hexadecimal, Octal, and Binary. We can write a number N in base or radix b as: 

Nb = dn-1 dn-2 -- -- -- -- dd0 . d-1 d-2 -- -- -- -- d-m

Here, dn-1 to d0 is the integer part, follows a radix point, and d-1 to d-m is the fractional part. 

dn-1 is the Most significant bit (MSB)

d-m is the Least significant bit (LSB)

Here is a list of some of the number systems used in computer science:

Decimal Number System

The decimal number system is a base 10 number system having ten digits from 0 to 9. It means that we can represent any numerical quantity using these ten digits. The decimal number system is also a positional value system. It means that the value of digits will depend on their position.

Binary Number System

The easiest way to run instructions through electric signals is a two-state system – on and off. On is represented as 1 and off as 0, though 0 is no signal but a lower voltage signal. The number system having only these two digits (0 & 1) is called a binary number system.

The rightmost digit is the LSB(least significant bit) in any binary number, and the leftmost digit is the MSB(most significant bit).

Octal Number System

The octal number system has eight digits - 0, 1, 2, 3, 4, 5, 6, and 7. The octal number system is a positional value system where each digit is expressed in powers of 8.

Hexadecimal Number System

The octal number system has 16 symbols from 0 to 9 and A to F where A is equal to 10 and B is equal to 11, until F. The Hexadecimal number system is also a positional value system where each digit has its value expressed in powers of 16.

Also Read - Shift Registers in Digital Electronics

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

Number System Relationship

The following table shows the association between binary, octal, decimal, and hexadecimal number systems.

BINARY

DECIMAL

OCTAL

HEXADECIMAL

0000

0

0

0

0001

1

1

1

0010

2

2

2

0011

3

3

3

0100

4

4

4

0101

5

5

5

0110

6

6

6

0111

7

7

7

1000

8

10

8

1001

9

11

9

1010

10

12

A

1011

11

13

B

1100

12

14

C

1101

13

15

D

1110

14

16

E

1111

15

17

F

 

Base Conversions

Here are a few of the most used base conversions:

Decimal to Binary

Step 1: Firstly, divide the decimal number by two and note the remainder.

Step 2: Divide the obtained quotient by 2, and note the remainder again.

Step 3: Then repeat the above steps until the quotient is 0.

Step 4: Write the remainders so that the last remainder is written first, followed by the rest in the reverse order.

Step 5: We can also understand this differently: the binary number's LSB(Least Significant Bit) is at the top, and the MSB(Most Significant Bit) is at the bottom. This number is the binary value of the given decimal number.

For Example: 1310 = 11012

Division by 2 Quotient Remainder
13 ÷ 2 6 1 (LSB)
6 ÷ 2 3 0
3 ÷ 2 1 1
1 ÷ 2 0 1 (MSB)

Binary to Decimal

The general formula for converting binary numbers to decimal numbers is:

Decimal Number10 = (d0 × 20) + (d1 × 21) + (d2 × 22) + ... + (dn−1 × 2n-1)

For Example: = (1 × 20) + (1 × 21) + (1 × 22) + (1 × 23)

 = 1 + 2 + 4 + 8

 = 15

Therefore, 11102 = 1510

Decimal to Octal

We divide a decimal number by eight each time we get a reminder from the previous digit.

Let us take a decimal number, i.e., 350.

Step 1: Check if the decimal number is less than 8. If yes, the octal number is the same. If no, then proceed forward. In this case, 350 is more than eight, so let's go to step 2.

Step 2: Divide 350 by 8 (octal base number). Note the quotient and the remainder in the quotient-remainder form. Repeat this process until we get the quotient to be less than 8.

Step 3: Once we obtain the quotient less than 8, we stop dividing to derive the octal number. The octal number is considered by reading all the remainders and the last quotient from bottom to top.

Therefore, 35010 = 5368

Octal to Decimal

Step 1: Write 140.2 with the power of 8. Start from the right-hand side.

1 × 82 + 4 × 81 + 0 × 80 + 2 × 8-1

Step 2: Evaluate the power of 8 values for each octal number.

82 = 64, 81 = 8, 80 = 1, 8-1 = 0.125

Step 3: Multiply each power of 8 numbers with the respective numbers.

1 × 64 + 4 × 8 + 0 × 1 + 2 × 0.125 = 64 + 32 + 0 + 0.25

Step 4: Add the values to obtain the decimal number.

64 + 32 + 0 + 0.25 = 96.25

Therefore, 140.28 = 96.2510

Hexadecimal to Binary

Convert hexadecimal numbers into binary numbers by following the steps given below:

Step 1: Take the given hexadecimal number and find the number of digits in the decimal.

Step 2: If it has N digits, multiply each digit with 16N-1, where the number is in the Nth position.

Step 3: Add the terms after multiplication.

Step 4: The decimal number is equivalent to the given hexadecimal number. Now we have to convert this into a binary number.

Step 5: Divide the decimal number with 2.

Step 6: Note the remainder.

Step 7: Do the above two steps for the quotient till the quotient is zero

Step 8: Write the remainders in reverse order.

Step 9: The result is the required binary number.

For example, Convert  3016 to Binary.

First, convert the given hexadecimal to the decimal number.

3016 = (3 × 161) + (0 × 160)

= 48 + 0

= 48(Decimal number)

Now we have to convert 4810 to binary.

Division by 2 Quotient Remainder
48 ÷ 2 24 0 (LSB)
24 ÷ 2 12 0
12 ÷ 2 6 0
6 ÷ 2 3 0
3 ÷ 2 1 1
1 ÷ 2 0 1 (MSB)

So the resultant binary number is 1100002.

Therefore, 3016 = 1100002
Must Read  C Program to Reverse a Number

Binary to Hexadecimal

For example, Convert (0111000101000) to Hexadecimal.

Firstly convert the binary number into a decimal number. For that, we multiply each digit with the corresponding power of two.

01110001010002 = 0 × 212 + 1 × 211 + 1 × 210 + 1 × 29 + 0 × 28 + 0 × 27 + 0 × 26 + 1 × 25 + 0 × 24 + 1 × 23 + 0 × 22 + 0 × 21 + 0 × 20

01110001010002 = 0 × 4096 + 1 × 2048 + 1 × 1024 + 1 × 512 + 0 × 256 + 0 × 128 + 0 × 64 + 1 × 32 + 0 × 16 + 1× 8 + 0 × 4 + 0 × 2 + 0 × 1

01110001010002 = 0 + 2048 + 1024 + 512 + 0 + 0 + 0 + 32 + 0 + 8 + 0 + 0 + 0

01110001010002 = 3624

Therefore, 01110001010012= 362410

ASCII

Besides numerical data, a computer must handle alphabets, punctuation marks, mathematical operators, special symbols, etc., that form the complete character set of the English language. The full set of characters or symbols is called alphanumeric codes. The complete alphanumeric code typically includes

  • 26 upper case letters
  • 26 lower case letters
  • 10 numeral digits
  • 7 punctuation marks
  • 20 to 40 special characters

A computer understands only numeric values, whatever we use the number system. So all characters should have a numeric equivalent or an alphanumeric code. The most widely used alphanumeric code is ASCII or American Standard Code for Information Interchange. ASCII is a 7-bit long code with 128 (27) potential codes.

Must read decimal to binary c++, Strong number in c

FAQs

  1. What are Number Systems?
    Number systems are a way of writing to express numbers. It is the mathematical notation representing numbers of a given set consistently using digits or other symbols. It delivers a unique representation of every integer and represents the arithmetic and algebraic structure of the figures.
     
  2. Define ISCII and UNICODE?
    ISCII stands for Indian Script Code for Information Interchange. We developed IISCII to support Indian languages on the computer. Language supported by IISCI includes Devanagari, Tamil, Bangla, Gujarati, Gurmukhi, Tamil, Telugu, etc. Government departments mostly use IISCI, and before it could catch on, a new universal encoding standard named Unicode came into play.
    Unicode is an international coding system designed with different language scripts. Each character or symbol is assigned a unique numeric value, mainly within the framework of ASCII. Earlier, each script had its encoding system, which could conflict.
     
  3. What are the advantages of the number systems in computers?
    Computer language utilizes a binary number system with zero representing an 'off' state and one representing an 'on' form. Benefits include ease of use in coding, fewer computations, and fewer computational errors. We can also use the binary number system in Boolean algebra.
     
  4. Why is Hexadecimal used?
    Hexadecimal is a base 16 system used to simplify representing binary. It means we can write an 8-bit binary number using only two hex digits, one hex digit for each nibble (or group of 4-bits). It is easier to write numbers as hexes than as binary numbers.
     
  5. Can computers use base 10?
    In theory, computers could use base 10, and some did historically. Any signal in a computer is voltage differentials. In a base-2 computer, there's low voltage and high voltage, corresponding to numeric 0 and 1, respectively.

Key Takeaways

This article teaches about Number Systems and how we use them. We saw types and interconversion of number systems and their value in programming.

For more information and dive deep into the world of programming, visit our guided path for ultimate guidance.

Check out our Interview Preparation course and blogs on Aptitude.

If you are preparing for your DSA interviews, then, Coding Ninjas Studio is a one-stop destination. This platform will help you acquire effective coding techniques and overview student interview experience in various product-based companies.

Happy Learning!

Next article
Complements
Live masterclass