 Explore Edit Edit

# Convert the given Binary Number into Decimal | FACE Prep

Published on 10 Mar 2020

Program to convert the given binary number into decimal number is discussed here. For example, the decimal equivalent of binary number 1111 is 15. Consider the binary number from the last.

For the above mentioned example,

1 * 2^0 = 1
1 * 2^1 = 2
1 * 2^2 = 4
1 * 2^3 = 6

Decimal number = 1 + 2 + 4 + 6 = 15

1111 in binary form is represented as 15 in decimal.


## Algorithm to convert the given binary number into 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.

## Program to convert the given binary number into decimal number

C
C++
Java
Python 3

Output
Input- Enter a binary number:11111111 Output- Decimal number :255

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.

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

﻿

C++
Java
Python 3

Output
Input- Enter a binary number:11111111 Output- Decimal number :255

Recommended Programs  