4.4.15.2.1 IsPowerOfTwo

#define IsPowerOfTwo( number) ((0u != (number)) && (((number) & ((number)-1u)) == 0u))

Algorithm to detect if a given number is a power of two. A number is a power of two if it has exactly one '1' in its binary representation. This is true if subtracting '1' from the number and doing an AND operation on the result with the number itself returns 0.

Parameters:
number

8-bit unsigned integer

Return values:
True

- The given number is a power of two

False

- The given number is not a power of two