Created
April 3, 2014 07:56
-
-
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…
This file contains hidden or 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
| 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