Count of even set bits between XOR of two arrays | C # program for the above approach ; Function that count the XOR of [ ] B with all the element in [ ] A having even set bit ; Count the set bits in A [ i ] ; check for even or Odd ; To store the count of element for [ ] B such that XOR with all the element in [ ] A having even set bit ; Count set bit for B [ i ] ; check for Even or Odd ; Driver Code
using System ; class GFG { static void countEvenBit ( int [ ] A , int [ ] B , int n , int m ) { int i , cntOdd = 0 , cntEven = 0 ; for ( i = 0 ; i < n ; i ++ ) { int x = bitCount ( A [ i ] ) ; if ( x % 2 == 1 ) { cntEven ++ ; } else { cntOdd ++ ; } } int [ ] CountB = new int [ m ] ; for ( i = 0 ; i < m ; i ++ ) { int x = bitCount ( B [ i ] ) ; if ( x % 2 == 1 ) { CountB [ i ] = cntEven ; } else { CountB [ i ] = cntOdd ; } } for ( i = 0 ; i < m ; i ++ ) { Console . Write ( CountB [ i ] + " ▁ " ) ; } } static int bitCount ( int x ) { int setBits = 0 ; while ( x != 0 ) { x = x & ( x - 1 ) ; setBits ++ ; } return setBits ; } public static void Main ( String [ ] args ) { int [ ] A = { 4 , 2 , 15 , 9 , 8 , 8 } ; int [ ] B = { 3 , 4 , 22 } ; countEvenBit ( A , B , 6 , 3 ) ; } }