Question

The sequence is:

00111011

How do i calculate the parity bit for the above sequence? This question is from Databases- The complete book by jeffery ullman (Exercise 13.4.1 a)

I am not sure what the answer to this question should be.

Is it as simple as :

i)Even Parity : the number of 1s is 5 (odd) so just append a 1 and the answer is : 001110111

ii)Odd Parity: likewise , just append 0: 001110110

OR:

am i on a totally wrong path here? I looked up on the net but could not find anything concrete . Also, the text for the above question in the text book is not clear.

Was it helpful?

Solution

Yes, your answers are correct. For the given sequence,

00111011

Odd Parity is 001110110, the parity bit is zero so that the total number of 1's in the code is 5, which is an Odd number.

The Even Parity is 001110111, the parity bit is one so that the total number of 1's in the code is 6, which is an Even number.

OTHER TIPS

You can also use XOR i.e; 00111011

0XOR0=0
0XOR0=0
0XOR1=1
1XOR1=0
0XOR1=1
1XOR0=1
1XOR1=0
0XOR1=1

, The last bit is the parity bit; 1 for even parity, 0 for odd parity. you should make this bit the LSB of the original number (00111011) thereby becoming (001110111).

unsigned char CalEvenParity(unsigned char data)
{
unsigned char parity=0;

while(data){
        parity^=(data &1);
        data>>=1;
            }
return (parity);
}

Alternate implementation of parity:

This involves doing an XOR between the consecutive bits in a particular number in an integer.

The x>>1 left shifts the value by 1 bit and the & 1, gets us the value of the last bit of the number.

Parity of the entire sequence can be visualized as below:- i.e due to the properties of XOR.

1 ^ 0 ^ 1 is same as (1 ^ 0 ) ^ 1 and we extend the same.

def parity_val(x):
    parity=0
    while x>>1:
     parity =  (x & 1)^ ((x >>1) & 1)
     x = x>> 1
    return parity
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top