We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 791f6e7 commit 8608038Copy full SHA for 8608038
Stack/P03_DecimalToBinary.py
@@ -0,0 +1,20 @@
1
+# Author: OMKAR PATHAK
2
+
3
+# Decimal to binary using Stack
4
5
+import Stack
6
7
+def dtob(decimal, base = 2):
8
+ myStack = Stack.Stack()
9
+ while decimal > 0:
10
+ myStack.push(decimal % base)
11
+ decimal //= base
12
13
+ result = ''
14
+ while not myStack.isEmpty():
15
+ result += str(myStack.pop())
16
17
+ return result
18
19
+if __name__ == '__main__':
20
+ print(dtob(15))
0 commit comments