Checking if a number is a power of 2 is a fundamental operation in computer science and mathematics. A power of 2 is a number that can be expressed as 2 raised to an integer power. For example, 8 is a power of 2 because it can be expressed as 23.
There are several ways to check if a number is a power of 2. One common method is to use the bitwise AND operator (&). When a number is ANDed with itself, the result is 0 if the number is even and the number itself if the number is odd. If the result of the AND operation is 0, then the number is a power of 2.