Created
June 6, 2017 06:44
-
-
Save mikkipastel/d68170ea40e402b0c2e84e18e5dffd7a to your computer and use it in GitHub Desktop.
Digital Circuit Design
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 decimal2base(num, base): | |
result = str() | |
while (num > 0): | |
old_num = num | |
num = int(num/base) | |
# reminder = int(num%base) | |
reminder = old_num - (num*base) | |
result = str(reminder) + result | |
if (base == 2): | |
print ("0b" + result) | |
elif (base == 16): | |
print ("0x" + result) | |
else: | |
print ("base = " + base + ", " +result) | |
return result | |
if __name__=="__main__": | |
decimal2base(37, 2) #bin(37) = 0b100101 | |
decimal2base(25, 2) #bin(37) = 0b11001 | |
decimal2base(32, 16) #hex(32) = 0x20 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment