Check division by 3 with binary operations?
问题 I've read this interesting answer about " Checking if a number is divisible by 3 " Although the answer is in Java , it seems to work with other languages also. Obviously we can do : boolean canBeDevidedBy3 = (i % 3) == 0; But the interesting part was this other calculation : boolean canBeDevidedBy3 = ((int) (i * 0x55555556L >> 30) & 3) == 0; For simplicity : 0x55555556L = "1010101010101010101010101010110" Nb There's also another method to check it : One can determine if an integer is