Created
December 15, 2009 06:19
-
-
Save rafacv/256732 to your computer and use it in GitHub Desktop.
Outputs numbers from 0 to 150 in BCD
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
| #!/usr/bin/env python | |
| bcd_digits = { | |
| "0": "0000", | |
| "1": "0001", | |
| "2": "0010", | |
| "3": "0011", | |
| "4": "0100", | |
| "5": "0101", | |
| "6": "0110", | |
| "7": "0111", | |
| "8": "1000", | |
| "9": "1001" | |
| } | |
| with open("bcds.txt", "w") as out: | |
| for number in range(151): | |
| bcd_number = [] | |
| for digit in str(number): | |
| bcd_number.append(bcd_digits[digit]) | |
| out.write("{0} - {1}\n".format(str(number).rjust(3, "0"), | |
| "".join(bcd_number).rjust(12, "0"))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment