fork(1) download
  1. def func(c):
  2. count = 0
  3. b = 0
  4. st = len(str(c))
  5. for i in str(c):
  6. count+=1
  7. st -= 1
  8. b += int(i) * 2**(st)
  9. return b
  10.  
  11. c = int(input("Введите число в двоичной системе счисления(пример - 10101): "))
  12. count = 0
  13. st = len(str(c))
  14. print("Алгоритм нахождения: ")
  15. for i in str(c):
  16. count+=1
  17. st -= 1
  18. if (count == len(str(c))):
  19. print("{0}*2^{1}".format(i,st))
  20. else:
  21. print("{0}*2^{1}".format(i,st), end = " + ")
  22. print("Число {0} в десятичной системе счисления - {1}".format(c,func(c)))
Success #stdin #stdout 0.1s 10104KB
stdin
10101
stdout
Введите число в двоичной системе счисления(пример - 10101): Алгоритм нахождения: 
1*2^4 + 0*2^3 + 1*2^2 + 0*2^1 + 1*2^0
Число 10101 в десятичной системе счисления - 21