def asr(a, b):
    """Arithmetic shift right
    Returns (result, carry)
    """
    b &= 31
    if b:
        if a & 0x80000000:
            a |= 0xffffffff00000000
        return (a >> b, 1 & (a >> (b-1)))
    else:
        return (a, 0)