Check if a number is divisible by 8 using bitwise operators | Java program to check whether the number is divisible by 8 or not using bitwise operator ; function to check number is div by 8 or not using bitwise operator ; Driver code
import java . io . * ; import java . util . * ; class GFG { static boolean Div_by_8 ( int n ) { return ( ( ( n >> 3 ) << 3 ) == n ) ; } public static void main ( String [ ] args ) { int n = 16 ; if ( Div_by_8 ( n ) ) System . out . println ( " YES " ) ; else System . out . println ( " NO " ) ; } }