Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Answer

deleted 40 characters in body
Source Link
xio
  • 650
  • 6
  • 11

You can use the following method

to multiple each of the binary digits with its corresponding value of 2 raised to the power to its index (position from right – 1) and sum them up.

binary = input('Binary number: ')
decimal = 0
binary_len = len(binary)
for x in binary:
 binary_len = binary_len - 1
 decimal += pow(2,binary_len) * int(x)
 
print(decimal)

input : 11111010010011000111

output : 1025223

You can see more details and examples in this articleMore examples

You can use the following method

to multiple each of the binary digits with its corresponding value of 2 raised to the power to its index (position from right – 1) and sum them up.

binary = input('Binary number: ')
decimal = 0
binary_len = len(binary)
for x in binary:
 binary_len = binary_len - 1
 decimal += pow(2,binary_len) * int(x)
 
print(decimal)

input : 11111010010011000111

output : 1025223

You can see more details and examples in this article

You can use the following method

to multiple each of the binary digits with its corresponding value of 2 raised to the power to its index (position from right – 1) and sum them up.

binary = input('Binary number: ')
decimal = 0
binary_len = len(binary)
for x in binary:
 binary_len = binary_len - 1
 decimal += pow(2,binary_len) * int(x)
 
print(decimal)

input : 11111010010011000111

output : 1025223

More examples

added 299 characters in body
Source Link
xio
  • 650
  • 6
  • 11

You can use the following method

to multiple each of the binary digits with its corresponding value of 2 raised to the power to its index (position from right – 1) and sum them up.

binary = input('Binary number: ')
decimal = 0
binary_len = len(binary)
for x in binary:
 binary_len = binary_len - 1
 decimal += pow(2,binary_len) * int(x)
 
print(decimal)

input : 11111010010011000111

output : 1025223

You can see more details and examples in this article

You can use the following method

binary = input('Binary number: ')
decimal = 0
binary_len = len(binary)
for x in binary:
 binary_len = binary_len - 1
 decimal += pow(2,binary_len) * int(x)
 
print(decimal)

input : 11111010010011000111

output : 1025223

You can use the following method

to multiple each of the binary digits with its corresponding value of 2 raised to the power to its index (position from right – 1) and sum them up.

binary = input('Binary number: ')
decimal = 0
binary_len = len(binary)
for x in binary:
 binary_len = binary_len - 1
 decimal += pow(2,binary_len) * int(x)
 
print(decimal)

input : 11111010010011000111

output : 1025223

You can see more details and examples in this article

Post Undeleted by xio
added 9 characters in body
Source Link
xio
  • 650
  • 6
  • 11

I think this is a simple solutionYou can use the following method

binary = int(input('Binary number: '))
decidecimal = 0
pbinary_len = 0len(binary)
while binary>0:
for qx =in binary//10:
 rbinary_len = binary%10
  binary_len deci- =1
 deci + r*2**p
 decimal += pow(2,binary_len) p* +=1int(x)
 binary = q
print(decidecimal)

input : 11111010010011000111

output : 1025223

I think this is a simple solution

binary = int(input('Binary number: '))
deci = 0
p = 0
while binary>0:
 q = binary//10
 r = binary%10
  deci = deci + r*2**p
 p +=1
 binary = q
print(deci)

input : 11111010010011000111

output : 1025223

You can use the following method

binary = input('Binary number: ')
decimal = 0
binary_len = len(binary)
for x in binary:
 binary_len = binary_len - 1
 decimal += pow(2,binary_len) * int(x)
 
print(decimal)

input : 11111010010011000111

output : 1025223

Post Deleted by xio
Source Link
xio
  • 650
  • 6
  • 11
Loading
lang-py

AltStyle によって変換されたページ (->オリジナル) /