Bitwise OR ( | ) of all even number from 1 to N | C # implementation of the above approach ; Function to return the bitwise OR of all the even numbers upto N ; Initialize result as 2 ; Driver code
using System ; 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 ( ) { int n = 10 ; Console . WriteLine ( bitwiseOrTillN ( n ) ) ; } }