mirror of
https://github.com/mnaberez/py65.git
synced 2025-01-04 01:30:18 +00:00
Added utility module.
This commit is contained in:
parent
cb7f82976f
commit
2f178e3fb7
@ -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
|
Loading…
Reference in New Issue
Block a user