Find if the given number is a power of 2 I am sure it has got something to do with bitwise operators, but for some reason, my brain aint working.
Nick Mason
take the biggest power of 2 that will fit in an int. Does your number divide it evenly? If so then it's a power of 2.
Ham Fisted
.... or an alternative:
msafar
That's darn clever. Although (unless you consider 1 to be a power of 2) I suggest
David Clayworth
David,
msafar
Fog Creek Home |