Electronic – Generate Event Parity with Logic Block

digital-logicparity

enter image description here

I was under the impression in order to generate 'Even Parity' you had to have an even number of bits… so how could that logic block only have one output?
I am sure I am wrong but I am not sure what to do..

Best Answer

A parity bit is used to detect single bit errors in a data stream. It does this by adding an extra bit, the parity bit. This bit is set to a value to ensure that the number of 1's in a word is even. So if there is an odd number of 1's in the data stream, the parity bit would be 1. If there are an even number already, the parity bit would be 0.

It makes no difference whether there are an even or odd number of bits in the data word, as the parity bit is counting the number of 1's, not the number of bits.


Some examples:

3 data bits + 1 parity bit

010 1
110 0
111 1
101 0

6 data bits + 1 parity bit

001000 1
101110 0
011001 1
100001 0

Notice how the parity bit ensures that there is an even number of 1's in every one of those words. In fact it works for any word of any length.


How is it calculated?

Quite simply actually. It is basically the bit sum of every bit in the stream, modulo 2. So you add each bit in turn, doing modulo 2 after each sum (*). This results in either a 0 or 1 which is the parity bit.


(*) You can actually do it at after summing all the bits if you want.