// count is 0 or 2^n, i.e. 0,1,2,4,8,16,.... if ((count & (count - 1)) == 0) { // do logging. } count++;