Binary to decimal conversion in python by R4R Team

Binary number

-It is a number which expressed in the base-2 numeral system,
-Binary numbers are 0 or 1.

Decimal number

- A number which expressed in the base-10 numeral system.
- Decimal number range is 0 to 9

Conversion of Binary to Decimal number

Example -
Binary number is 1010
Its decimal equivalent is 10

Binary number is 100000000000
Its decimal equivalent is 2048

program -

print("Enter Binary number")
n=int(input())
s=0
i=0
while(n>0):
t=n%10
s=s+t*(2**i)
n=int(n/10)
i=i+1

print("Decimal equivalent is - "+str(s))


output -

Enter Binary number
111111111
Decimal equivalent is - 511

Enter Binary number
100000000000
Decimal equivalent is - 2048


-In this program, we take input of the binary number, then for each bit of number we convert the decimal equivalent and add them so we get decimal number of given number.



Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!