Created
March 25, 2020 15:30
-
-
Save coci/16458544cbfc5cabb316e5c2d0dadffc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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