def bw24(x):
    """Return the bit weight of the lowest 24 bits of x"""
    x = (x & 0x555555) + ((x & 0xaaaaaa) >> 1)
    x = (x & 0x333333) + ((x & 0xcccccc) >> 2)
    x = (x + (x >> 4)) & 0xf0f0f
    return (x + (x >> 8) + (x >> 16)) & 0x1f