{"id":8276,"date":"2021-06-07T18:07:44","date_gmt":"2021-06-07T12:37:44","guid":{"rendered":"https:\/\/python-programs.com\/?p=8276"},"modified":"2021-11-22T18:38:39","modified_gmt":"2021-11-22T13:08:39","slug":"python-program-to-find-whether-a-number-is-a-power-of-two","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-find-whether-a-number-is-a-power-of-two\/","title":{"rendered":"Python Program to Find Whether a Number is a Power of Two"},"content":{"rendered":"

In this tutorial, the power of 2 or not for python programming can be checked. The user gives a positive integer N and we have to check if it is equivalent to 2^x or not, where x can be zero or a number positive.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

given number =2048<\/pre>\n

Output:<\/strong><\/p>\n

The given numb 2048 is power of 2<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

given number =256<\/pre>\n

Output:<\/strong><\/p>\n

The given numb 256 is power of 2<\/pre>\n

Example3:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

given number =678<\/pre>\n

Output:<\/strong><\/p>\n

The given numb 678 is not power of 2<\/pre>\n

Program to Find Whether a Number is a Power of Two in Python<\/h2>\n

There are several ways to check whether the given number is a power of 2 or not some of them are:<\/p>\n