Python for Engineers
Solve Problems by Coding Solutions
Blog Pages
Blog
Online Compiler
NumPy
Distributions
Self Learning
IDE
Online Tools
About
Binary Number to Decimal Conversion
k=int(raw_input('Enter the binary number:'))
b=k
c=0
while b>0:
b=b/10
c=c+1
print c
n=0
sum=0
while n<c:
r=k%10
k=k/10
sum=sum + (r*(2**n))
n=n+1
print 'Decimal Number is:', sum
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment