File tree Expand file tree Collapse file tree
Binary to Decimal Converter Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <div align =" center " >
2+
3+ # Binary to Decimal Converter
4+
5+ </div >
6+
7+ ### Description:
8+ This Python script converts a binary number to its equivalent decimal representation.
9+
10+ ### How to Use:
11+ 1 . Run the script in a Python environment.
12+ 2 . Enter a binary number when prompted.
13+ 3 . The script will convert the binary number to its decimal equivalent and display the result.
Original file line number Diff line number Diff line change 1+ def binary_to_decimal (binary ):
2+ decimal = 0
3+ for digit in binary :
4+ decimal = decimal * 2 + int (digit )
5+ return decimal
6+
7+
8+ def main ():
9+ binary = input ("Enter a binary number: " )
10+ decimal = binary_to_decimal (binary )
11+ print (f"The decimal equivalent of { binary } is { decimal } ." )
12+
13+
14+ if __name__ == "__main__" :
15+ main ()
You can’t perform that action at this time.
0 commit comments