odd question

Jiri Barton jbar at hosting4u.cz
Wed Jul 14 22:20:03 CEST 2004


Hey again,

this f2 might be useful when doing the binary addition:

def addthem(m, n):
    """m + n"""

    transition = 0
    result = []
    while m | n | transition:
        transition = f2(m & 1, n & 1, transition)
        result.insert(0, (m ^ n ^ transition) & 1)
        m >>= 1
        n >>= 1
    return result

However, I don't know how to create an integer, because I need to insert the
current bit at the beginning of the result integer that is being created -
I don't know how to do it with just shifting operations, so I used the
list:-)

jbar




More information about the Python-list mailing list