bitwise operation & clever loop condition