Program to find parity | Function to get parity of number n . It returns 1 if n has odd parity , and returns 0 if n has even parity ; Driver Code
< ? php function getParity ( $ n ) { $ parity = 0 ; while ( $ n ) { $ parity = ! $ parity ; $ n = $ n & ( $ n - 1 ) ; } return $ parity ; } $ n = 7 ; echo " Parity ▁ of ▁ no ▁ " , $ n , " ▁ = ▁ " , getParity ( $ n ) ? " odd " : " even " ; ? >