text: 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
code: function getParity ( n ) { var parity = false ; while ( n != 0 ) { parity = ! parity ; n = n & ( n - 1 ) ; } return parity ; } var n = 7 ; document . write ( " " + n + " " + ( getParity ( n ) ? " " : " " ) ) ;