Skip to content

Instantly share code, notes, and snippets.

@rafacv
Created December 15, 2009 06:19
Show Gist options
  • Select an option

  • Save rafacv/256732 to your computer and use it in GitHub Desktop.

Select an option

Save rafacv/256732 to your computer and use it in GitHub Desktop.
Outputs numbers from 0 to 150 in BCD
#!/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