“怎么将一串数字转换为BCD码?”BCD就是Binary-Coded Decimal 。下面是Python的一种思路:def dec2bcd(num): new = '' for i in str(num): bNum= bin(int(i)).replace('0b','').zfill(4) new= new + bNum return new比如:dec2bcd(819), 结果是100000011001
def dec2bcd(num): new = '' for i in str(num): bNum= bin(int(i)).replace('0b','').zfill(4) new= new + bNum return new