Convert the given Binary Number into Decimal | faceprep

Convert the given Binary Number into Decimal | faceprep

The program to convert the given binary number into a decimal number is discussed here. For example, the decimal equivalent of the binary number 1111 is 15.



Convert the given Binary Number into Decimal


Convert the given Binary Number into Decimal


Consider the binary number from the last.nnFor the above mentioned example,nn1 * 2^0 = 1n1 * 2^1 = 2n1 * 2^2 = 4n1 * 2^3 = 6nnDecimal number = 1 + 2 + 4 + 6 = 15nn1111 in binary form is represented as 15 in decimal.n


Algorithm to convert the given binary number into a decimal number

  • Input the binary number.
  • Multiply each digit of the binary number with the power of 2 and add each multiplication result.
  • The power starts from 0 to n-1 where n is the total number of digits in the binary number.


Convert the given Binary Number into Decimal

Program to convert the given binary number into a decimal number

@@coding::1@@


The above program works only with binary numbers given in the range of integers (-32767 to 32767). To work with long binary numbers (greater range of numbers with 20 bits or 30 bits), a string variable is used to store the binary numbers.

A program to convert numbers from binary numbers of higher range to decimal is given below

@@coding::2@@



Convert the given Binary Number into Decimal



Recommended Programs








Convert the given Binary Number into Decimal

c