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: