<< - bitwise shift operator to the left ; it shifts the bit of the value remaining by the specified amount. Thus, 1L<<(32-maskbits) shifts the value 1 left 32-maskbits times.
& is a bitwise AND operator .
So, the loop expression mask & (1L<<(32-maskbits)) == 0 checks all bits within the mask value, from lower to higher. The loop will stop at the first (minimum) non-zero mask bit, in which the maskbits point will contain the number of bits higher (and include) this bit.
eg.
- if
mask == 0xFFFF mask == 0xFFFFFFFF (== binary 11111111111111111111111111111111) , the loop will stop at the first iteration, and maskbits will be 32 - if
mask == 0x0001 mask == 0x00000001 (== binary 00000000000000000000000000000001) , the loop will stop at the first iteration again, and maskbits will be 32 - if
mask == 0x1000 mask == 0x01000000 (== binary 00000001000000000000000000000000) , the loop will stop at the 24th iteration, and maskbits will be 8
source share