CBSE Class 11 Informatics Practices
Question 28 of 36
Conditional and Looping Constructs — Question 28
Back to all questions 28
Question WAP to convert binary number to decimal number.
binary = input("Enter a binary number: ")
decimal = 0
for digit in binary:
decimal = decimal * 2 + int(digit)
print("The decimal equivalent of", binary, "is", decimal)Enter a binary number: 110
The decimal equivalent of 110 is 6
binary
=
input
(
"Enter a binary number: "
)
decimal
=
0
for
digit
in
binary
:
decimal
=
decimal
*
2
+
int
(
digit
)
print
(
"The decimal equivalent of"
,
binary
,
"is"
,
decimal
)
Output
Enter a binary number: 110
The decimal equivalent of 110 is 6