Skip to content

Instantly share code, notes, and snippets.

@eirenik0
Created April 3, 2014 07:56
Show Gist options
  • Save eirenik0/9950161 to your computer and use it in GitHub Desktop.
Save eirenik0/9950161 to your computer and use it in GitHub Desktop.
In your study of computer science, you have probably been exposed in one way or another to the idea of a binary number. Binary representation is important in computer science since all values stored within a computer exist as a string of binary digits, a string of 0s and 1s. Without the ability to convert back and forth between common representa…
def divideBy2(decNumber):
remstack = Stack()
while decNumber > 0:
rem = decNumber % 2
remstack.push(rem)
decNumber = decNumber // 2
binString = ""
while not remstack.isEmpty():
binString = binString + str(remstack.pop())
return binString
print(divideBy2(42))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment