0 menonnik 6 Years Ago How can we calculate whether a number is a power of 2 or not in a single statement without using a loop? All the ones that I can think of use loops or don't satisfy the condition. for eg. The use of XOR doesn't work as it gives incorrect input. or maybe I'm not using it in a proper manner. c power

0 Salem 5,138 6 Years Ago If n is a power of 2, look at the value in binary. Then look at the binary representation of n-1

0 OPDiscussion Starter menonnik 6 Years Ago ok. should i just check if it's binary representation has a single 1. but how can we implement it without a loop.