bit masking tricks
Certainly! Here is a response:
Set a bit: To set a specific bit in a number to 1, use the bitwise OR operator with a mask that has 1 at the bit position to be set.
Clear a bit: To clear a specific bit in a number to 0, use the bitwise AND operator with a mask that has 0 at the bit position to be cleared.
Toggle a bit: To toggle a specific bit in a number (change 1 to 0 or 0 to 1), use the bitwise XOR operator with a mask that has 1 at the bit position to be toggled.
Check if a bit is set: To check if a specific bit is set (equals 1) in a number, use the bitwise AND operator with a mask that has 1 at the bit position to be checked.
Check if a bit is clear: To check if a specific bit is clear (equals 0) in a number, use the bitwise AND operator with a mask that has 0 at the bit position to be checked.