Skip to content

Commit e15e8af

Browse files
committed
Added Binary to Decimal Converter script
1 parent 1fe61af commit e15e8af

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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()

0 commit comments

Comments
 (0)