Bitwise AND of all the odd numbers from 1 to N | Java implementation of the approach ; Function to return the bitwise AND of all the odd integers from the range [ 1 , n ] ; Initialize result to 1 ; Starting from 3 , bitwise AND all the odd integers less than or equal to n ; Driver code
class GFG { static int bitwiseAndOdd ( int n ) { int result = 1 ; for ( int i = 3 ; i <= n ; i = i + 2 ) { result = ( result & i ) ; } return result ; } public static void main ( String [ ] args ) { int n = 10 ; System . out . println ( bitwiseAndOdd ( n ) ) ; } }