Finding the Parity of a number Efficiently | Function to find the parity ; Rightmost bit of y holds the parity value if ( y & 1 ) is 1 then parity is odd else even ; Driver code
function findParity ( x ) { let y = x ^ ( x >> 1 ) ; y = y ^ ( y >> 2 ) ; y = y ^ ( y >> 4 ) ; y = y ^ ( y >> 8 ) ; y = y ^ ( y >> 16 ) ; if ( y & 1 ) return 1 ; return 0 ; } ( findParity ( 9 ) == 0 ) ? document . write ( " " ) : document . write ( " " ) ; ( findParity ( 13 ) == 0 ) ? document . write ( " " ) : document . write ( " " ) ;