- Related Questions & Answers
- C Program for Tower of Hanoi
- C++ Program for Dijkstra’s shortest path algorithm?
- C/C++ Program for nth Catalan Number?
- C Program to Multiply two Floating Point Numbers?
- C program to find the length of a string?
- C Program to Check if all digits of a number divide it
- C Program to Check if a Given String is a Palindrome?
- Write a program to Delete a Tree in C programming
- Write a C program to print “ Tutorials Point ” without using a semicolon
- Sum of the nodes of a Singly Linked List in C Program
- Sum of first n natural numbers in C Program
- C Program for simple interest?
- Area of a n-sided regular polygon with given Radius in C Program?
- Area of a leaf inside a square in C Program?
- C Program for Area of a square inscribed in a circle which is inscribed in a hexagon?

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

In this article, we will learn about the solution to the problem statement given below.

**Problem statement **− We are given a number, we need to check that the number is a power of two or not.

We can solve this using two approaches as discussed below.

# power of 2 def find(n): if (n == 0): return False while (n != 1): if (n % 2 != 0): return False n = n // 2 return True # Driver code if(find(98)): print('Yes') else: print('No')

No

# power of 2 def find(x): # if x is 0 or not return (x and (not(x & (x - 1))) ) # Driver code if(find(98)): print('Yes') else: print('No')

No

In this article, we have learned how we can check that the given number is a power of two.

Advertisements