[23771 views]
A number system with a base 10 is known as decimal number system. Hence, decimal numbers are denoted with a base 10.
This number system consists of 10 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. Each digit in the decimal system has a position and every digit is ten times more significant than the previous digit.
For example: (461)10 , (370)10 , (890)10 , (400)10 , etc.
A number system with a base 2 is known as binary number system. Hence, binary numbers are denoted with a base 2. It consists of two values: 0 and 1.
Each digit in this system is said to be a bit. For example: (110101)2, (10101101)2, (10000)2, (10)2, etc.
We will start off by taking the number to be converted as user input. The idea behind this conversion is to extract the last digit from the number one at a time and multiply it with 2 to the power of the number’s position. This process is repeated for all the digits of the number. After this, all these products are added and the final sum is the corresponding decimal number. Let us take a look at an example for better understanding:
Given binary number: (10110)2
Corresponding decimal number = (1*24) + (0*23) + (1*22) + (1*21) + (0*20)
= 16 + 0 + 4 + 2 + 0
= 22