Skip to content

Created octal_to_binary.py and fixed issue #8921 #8951

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from
19 changes: 19 additions & 0 deletions conversions/octal_to_binary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
def octal_to_binary(octal):
# Converting Octal to Decimal
decimal = 0
power = 0
while octal != 0:
decimal += (octal % 10) * pow(8, power)
octal //= 10
power += 1
# Converting Decimal to Binary
binary = 0
digit_place = 1
while decimal != 0:
binary += (decimal % 2) * digit_place
decimal //= 2
digit_place *= 10
return binary
octal_number = int(input("Enter octal number: "))
binary_number = octal_to_binary(octal_number)
print(f"The binary equivalent of {octal_number} is {binary_number}")