Count minimum bits to flip such that XOR of A and B equal to C | PHP code to count the Minimum bits in A and B ; If both A [ i ] and B [ i ] are equal ; If Both A and B are unequal ; N represent total count of Bits
< ? php function totalFlips ( $ A , $ B , $ C , $ N ) { $ count = 0 ; for ( $ i = 0 ; $ i < $ N ; ++ $ i ) { if ( $ A [ $ i ] == $ B [ $ i ] && $ C [ $ i ] == '1' ) ++ $ count ; else if ( $ A [ $ i ] != $ B [ $ i ] && $ C [ $ i ] == '0' ) ++ $ count ; } return $ count ; } $ N = 5 ; $ a = "10100" ; $ b = "00010" ; $ c = "10011" ; echo totalFlips ( $ a , $ b , $ c , $ N ) ; ? >