1
0
mirror of https://github.com/mnaberez/py65.git synced 2024-10-06 22:56:17 +00:00

Added utility module.

This commit is contained in:
Mike Naberezny 2008-09-08 03:25:28 +00:00
parent cb7f82976f
commit 2f178e3fb7

View File

@ -1,10 +1,23 @@
def itoa(num, base=10):
negative = num < 0
if negative:
num = -num
digits = []
while num > 0:
num, last_digit = divmod(num, base)
digits.append('0123456789abcdefghijklmnopqrstuvwxyz'[last_digit])
if negative:
digits.append('-')
digits.reverse()
return ''.join(digits)
def convert_to_bin(bcd):
return bcd2bin[bcd]
def convert_to_bcd(bin):
return bin2bcd[bin]
bcd2bin = [
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, # 0x00
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, # 0x10