Bitwise OR ( | ) of all even number from 1 to N | Java implementation of the above approach ; Function to return the bitwise OR of all the even numbers upto N ; Initialize result as 2 ; Driver code
class GFG { static int bitwiseOrTillN ( int n ) { int result = 2 ; for ( int i = 4 ; i <= n ; i = i + 2 ) { result = result | i ; } return result ; } static public void main ( String args [ ] ) { int n = 10 ; System . out . println ( bitwiseOrTillN ( n ) ) ; } }