Skip to content
Subhajit Sahu edited this page Jan 24, 2021 · 7 revisions

Get n-bit parity. 📰 📘

Similar: count, parity.


Bit.parity(x, [n]);
// x: an int or long
// n: number of bits (1)
import io.github.javaf.*;

Bit.parity(7);
// 1 (1,1,1 ⇒ 1)

Bit.parity(5);
// 0 (1,0,1 ⇒ 0)

Bit.parity(8, 2);
// 2 (10,00 ⇒ 10)

Bit.parity(63, 4);
// 12 (11,1111 ⇒ 1100)


References

Clone this wiki locally