- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions

# Check if n is divisible by power of 2 without using arithmetic operators in Python

Suppose we have two numbers x and n. We have to check whether x is divisible by 2^n or not without using arithmetic operators.

So, if the input is like x = 32 n = 5, then the output will be True as 32 = 2^5.

To solve this, we will follow these steps −

- if x AND (2^n - 1) is 0, then
- return True

- return False

## Example

Let us see the following implementation to get better understanding −

def solve (x, n): if (x & ((1 << n) - 1)) == 0: return True return False x = 32 n = 5 print(solve(x, n))

## Input

32, 5

## Output

True

- Related Articles
- Check if product of first N natural numbers is divisible by their sum in Python
- Check if a number is multiple of 5 without using / and % operators in C++
- Python Arithmetic Operators
- How to sum two integers without using arithmetic operators in C/C++?
- Check if given number is a power of d where d is a power of 2 in Python
- How to sum two integers without using arithmetic operators in C/C++ Program?
- Check if 74526 is divisible by 3.
- Check if any permutation of a large number is divisible by 8 in Python
- Check if Decimal representation of an Octal number is divisible by 7 in Python
- Check if N is divisible by a number which is composed of the digits from the set {A, B} in Python
- Check if any permutation of N equals any power of K in Python
- Check if any large number is divisible by 17 or not in Python
- Check if any large number is divisible by 19 or not in Python
- Check if any permutation of a number is divisible by 3 and is Palindromic in Python
- Program to check if array pairs are divisible by k or not using Python

Advertisements