Skip to content

Instantly share code, notes, and snippets.

@coci
Created March 25, 2020 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coci/16458544cbfc5cabb316e5c2d0dadffc to your computer and use it in GitHub Desktop.
Save coci/16458544cbfc5cabb316e5c2d0dadffc to your computer and use it in GitHub Desktop.
class Stack:
def __ini__(self):
self.array = []
def push(self,item):
self.array.append(itme)
def pop(self):
return self.array.pop()
def isEmpty(self):
return True if len(array) > 0 else False
def decimal_to_binary(number):
s = Stack()
while number > 0 :
s.push(number % 2)
number = number // 2
binary_number = ""
while not s.isEmpty():
binary_number = binary_number + str(s.pop())
return binary_number
>>> print(decimal_to_binary(233))
>>> '11101001'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment