We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent ae0fc85 commit 9da661bCopy full SHA for 9da661b
conversions/octal_to_binary.py
@@ -0,0 +1,22 @@
1
+def octal_to_binary(octal):
2
+ # Converting Octal to Decimal
3
+ decimal = 0
4
+ power = 0
5
+ while octal != 0:
6
+ decimal += (octal % 10) * pow(8, power)
7
+ octal //= 10
8
+ power += 1
9
+
10
+ # Converting Decimal to Binary
11
+ binary = 0
12
+ digit_place = 1
13
+ while decimal != 0:
14
+ binary += (decimal % 2) * digit_place
15
+ decimal //= 2
16
+ digit_place *= 10
17
18
+ return binary
19
20
+octal_number = int(input("Enter octal number: "))
21
+binary_number = octal_to_binary(octal_number)
22
+print(f"The binary equivalent of {octal_number} is {binary_number}")
0 commit comments