Today I needed a simple algorithm for checking if a number is a power of 2.
The algorithm needs to be:
ulong
bool IsPowerOfTwo(ulong x) { return x > 0 && (x & (x - 1)) == 0; }