write a program in C# to Check whether given number is power of 2 or not | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

write a program in C# to Check whether given number is power of 2 or not

24th Nov 2016, 4:43 PM
Deepashri Bharat Barve
Deepashri Bharat Barve - avatar
1 Answer
+ 3
if((x != 0) && ((x & (x - 1)) == 0)) { //the number is power of 2. }
24th Nov 2016, 6:18 PM
Cyrus Ornob Corraya
Cyrus Ornob Corraya - avatar