def toBCD (n):

    """Converts the number n into Binary Coded Decimal."""
    bcd  = 0
    bits = 0

    while True:
        n, r  = divmod(n, 10)
        bcd  |= (r << bits)
        if n is 0:
            break
        bits += 4

    return bcd