Exemplo n.º 1
0
def dec_to_bcd_excess3(num, bias=3):
    """Converts a binary to Binary Coded Decimal, then converts again to
    excess-3 BCD, which has a 'bit bias' of `bias`, where bits are
    shifted by the given bias. See wikipedia.org/wiki/Excess-3 for more."""
    bcd, binary, decimals = '', '', ''
    for digit in str(num):
        binval = encoders.dec_to_bin(int(digit))
        binval = BaseDataType.add(str(binval), bias)
        binary += '{}{}'.format(binval, ' ' * (4 - len(binval) + 1))
        if len(binval) < 4:
            binval = binval.zfill(4)
        bcd += '{} '.format(binval)
        decimals += digit + (' ' * 4)
    _show_bcd(num, decimals, binary, bcd)
    return bcd
Exemplo n.º 2
0
Arquivo: bcd.py Projeto: Androbos/MoAL
def dec_to_bcd_excess3(num, bias=3):
    """Converts a binary to Binary Coded Decimal, then converts again to
    excess-3 BCD, which has a 'bit bias' of `bias`, where bits are
    shifted by the given bias. See wikipedia.org/wiki/Excess-3 for more."""
    bcd, binary, decimals = '', '', ''
    for digit in str(num):
        binval = encoders.dec_to_bin(int(digit))
        binval = BaseDataType.add(str(binval), bias)
        binary += '{}{}'.format(binval, ' ' * (4 - len(binval) + 1))
        if len(binval) < 4:
            binval = binval.zfill(4)
        bcd += '{} '.format(binval)
        decimals += digit + (' ' * 4)
    _show_bcd(num, decimals, binary, bcd)
    return bcd