Search code examples
network-programmingparity

What is the correct parity for this bit sequence?


I have the following bit sequence and I am trying to determine it's parity but I am insure of the answer.

1010101010101011

Since the number of 1's is 9, can I assume that the parity is odd?


Solution

  • Yes. The parity of this sequence is odd, as shown by this tool:

    var input = document.getElementById("bits");
    var parity = document.getElementById("parity");
    input.addEventListener("keyup", function(e) {
      this.value = this.value.replace(/[^01]/g, "");
      parity.innerText = this.value ? (this.value.match(/1/g)||[]).length % 2 ? "odd" : "even" : "";
    });
    <input id="bits"/><br />
    Parity: <span id="parity"></span>