Check if n is divisible by power of 2 without using arithmetic operators | JAVA Code for Check if n is divisible by power of 2 without using arithmetic operators ; function to check whether n is divisible by pow ( 2 , m ) ; if expression results to 0 , then n is divisible by pow ( 2 , m ) ; n is not divisible ; Driver program to test above function
import java . util . * ; class GFG { static boolean isDivBy2PowerM ( int n , int m ) { if ( ( n & ( ( 1 << m ) - 1 ) ) == 0 ) return true ; return false ; } public static void main ( String [ ] args ) { int n = 8 , m = 2 ; if ( isDivBy2PowerM ( n , m ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }