Skip to content
Subhajit Sahu edited this page Feb 2, 2021 · 13 revisions

Get n-bit parity. 📦 😺 🏃 📼 🌔 📜 📰 📘

Similar: count, parity.


bit.parity(x, [n]);
// x: an int32
// n: number of bits (1)
const bit = require("extra-bit");

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