# How to understand and use bit operation for programming

I got the following code using bit operation from here:

lis = Complement[Range[0, 15], {7, 14, 15}]
ans = Tuples[lis, 3] //
Select[#,
BitAnd[#1, #2, #3] == 0 && BitAnd[4 #1, 2 #2, #3] == 0 &&
BitAnd[#1, 2 #2, 4 #3] == 0 & @@ # &] &;
nums = Length@ans
GroupBy[ans,
Total@Flatten@IntegerDigits[#, 2] &] // #[Max[Keys[#]]] & //
IntegerDigits[#, 2, 4] & // TableForm /@ # &


But I'm not familiar with bit operations. How can I understand the meaning of this code and find more examples of bit operations?

• This code treats four-bit integers as arrays of four Boolean values (represented by binary digits 0 and 1). The selection code filters out cases where there's a binary 1-digit on the same, incrementing or decrementing position of the binary representations (or the array positions) of tuple values using the BitAnd operation (multiplication by a power of two acts as a position shifter). – kirma Mar 15 '20 at 6:46
• @kirma Thank you very much for your comment, which makes me understand the operation mechanism of this code. – A little mouse on the pampas Mar 15 '20 at 7:14
• Copied the comment to an answer, as it seems to resolve the issue... – kirma Mar 15 '20 at 9:01

This code treats four-bit integers as arrays of four Boolean values (represented by binary digits 0 and 1). The selection code filters out cases where there's a binary 1-digit on the same, incrementing or decrementing position of the binary representations (or the array positions) of tuple values using the BitAnd operation (multiplication by a power of two acts as a position shifter).