text: Maximize the expression ( A AND X ) * ( B AND X ) | Bit Manipulation | C # implementation of the approach ; Function to find X according to the given conditions ; int can have 32 bits ; Temporary ith bit ; Compute ith bit of X according to given conditions Expression below is the direct conclusion from the illustration we had taken earlier ; Add the ith bit of X to X ; Driver code
code: using System ; class GFG { static int MAX = 32 ; static int findX ( int A , int B ) { int X = 0 ; for ( int bit = 0 ; bit < MAX ; bit ++ ) { int tempBit = 1 << bit ; int bitOfX = A & B & tempBit ; X += bitOfX ; } return X ; } public static void Main ( String [ ] args ) { int A = 11 , B = 13 ; Console . WriteLine ( findX ( A , B ) ) ; } }