Bitwise AND of all the odd numbers from 1 to N | 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
function bitwiseAndOdd ( n ) { var result = 1 ; for ( var i = 3 ; i <= n ; i = i + 2 ) { result = ( result & i ) ; } return result ; } var n = 10 ; document . write ( bitwiseAndOdd ( n ) ) ;