Is A Power Of 2
easy
1. You are given a number n. 2. You have to check whether it is a power of 2 or not.
Constraints
1 <= n <= 10^9
Format
Input
A number n
Output
true/false
Example
Sample Input
1024
Sample Output
true
Question Video
{"id":"590bc055-5c58-4109-a225-2be61f2b90a7","name":"Is A Power Of 2","description":"1. You are given a number n.\r\n2. You have to check whether it is a power of 2 or not.","inputFormat":"A number n","outputFormat":"true/false","constraints":"1 <= n <= 10^9","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\n\nint main(){\n int n;\n cin>>n;\n // write your code\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args){\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n //write your code here\r\n \r\n }\r\n\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"1024","sampleOutput":"true\r\n","questionVideo":"https://www.youtube.com/embed/I80Ovvi_nRU?end=292","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"f3e3dbef-d2b7-4f6d-b357-2ef3738e6c91","name":"Bit Manipulation For Intermediate","slug":"bit-manipulation-for-intermediate-9995","type":0},{"id":"9d2722d1-86c7-43c4-9e9f-c3f64c0163c8","name":"Is A Power Of 2","slug":"is-a-power-of-2","type":1}],"next":{"id":"0d0f300d-cea5-4dbb-bca3-3d7ab8a9e0b0","name":"Is a Power of 2 MCQ","type":0,"slug":"is-a-power-of-2-mcq"},"prev":{"id":"7fc34d95-e62b-4cc4-9309-4e0c6cff003f","name":"COPY SET BITS IN A RANGE","type":3,"slug":"copy-set-bits-in-a-range"}}}
1. You are given a number n. 2. You have to check whether it is a power of 2 or not.
{"id":"590bc055-5c58-4109-a225-2be61f2b90a7","name":"Is A Power Of 2","description":"1. You are given a number n.\r\n2. You have to check whether it is a power of 2 or not.","inputFormat":"A number n","outputFormat":"true/false","constraints":"1 <= n <= 10^9","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\n\nint main(){\n int n;\n cin>>n;\n // write your code\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args){\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n //write your code here\r\n \r\n }\r\n\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"1024","sampleOutput":"true\r\n","questionVideo":"https://www.youtube.com/embed/I80Ovvi_nRU?end=292","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"f3e3dbef-d2b7-4f6d-b357-2ef3738e6c91","name":"Bit Manipulation For Intermediate","slug":"bit-manipulation-for-intermediate-9995","type":0},{"id":"9d2722d1-86c7-43c4-9e9f-c3f64c0163c8","name":"Is A Power Of 2","slug":"is-a-power-of-2","type":1}],"next":{"id":"0d0f300d-cea5-4dbb-bca3-3d7ab8a9e0b0","name":"Is a Power of 2 MCQ","type":0,"slug":"is-a-power-of-2-mcq"},"prev":{"id":"7fc34d95-e62b-4cc4-9309-4e0c6cff003f","name":"COPY SET BITS IN A RANGE","type":3,"slug":"copy-set-bits-in-a-range"}}}
Editor
Discussions
Show Discussion
Related Resources