Bitwise AND of all unordered pairs from a given array | Function to calculate bitwise AND of all pairs from the given array ; Stores bitwise AND of all possible pairs ; Generate all possible pairs ; Calculate bitwise AND of each pair ; Driver Code
function TotalAndPair ( arr , N ) { let totalAND = ( 1 << 30 ) - 1 ; for ( let i = 0 ; i < N ; i ++ ) { for ( let j = i + 1 ; j < N ; j ++ ) { totalAND &= arr [ i ] & arr [ j ] ; } } return totalAND ; } let arr = [ 4 , 5 , 12 , 15 ] ; let N = arr . length ; document . write ( TotalAndPair ( arr , N ) ) ;