Given two positive integers n and m. The problem is to check whether n is divisible by 2m or not without using arithmetic operators.
Input : n = 8, m = 2 Output : Yes Input : n = 14, m = 3 Output : No
Approach: If a number is divisible by 2 then it has its least significant bit (LSB) set to 0, if divisible by 4 then two LSB’s set to 0, if by 8 then three LSB’s set to 0 and so on. Keeping this in mind, a number n is divisible by 2m if (n & ((1 << m) – 1)) is equal to 0 else not.
- Smallest perfect power of 2 greater than n (without using arithmetic operators)
- Check if two numbers are equal without using arithmetic and comparison operators
- Check if a number is divisible by 8 using bitwise operators
- Check if a number is divisible by 17 using bitwise operators
- Subtract 1 without arithmetic operators
- Add two numbers without using arithmetic operators
- Subtract two numbers without using arithmetic operators
- Check if given number is a power of d where d is a power of 2
- Check if a number is power of 8 or not
- Check if bitwise AND of any subset is power of two
- Check if a number is positive, negative or zero using bit operators
- Check if a number is multiple of 9 using bitwise operators
- Check if two numbers are equal without using comparison operators
- Operators in C | Set 2 (Relational and Logical Operators)
- Bitwise Operators in C/C++
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : jit_t