Calculate n-bit parity.
Similar: count, parity.
parity(x, [n]) // x: an int32 // n: number of bits (1)
const xbit = require('extra-bit'); xbit.parity(7); // → 1 (1,1,1 ⇒ 1) xbit.parity(5); // → 0 (1,0,1 ⇒ 0) xbit.parity(8, 2); // → 2 (10,00 ⇒ 10) xbit.parity(63, 4); // → 12 (11,1111 ⇒ 1100)
There was an error while loading. Please reload this page.