answersLogoWhite

0

# include

# define bool int

/* Function to get parity of number n. It returns 1

if n has odd parity, and returns 0 if n has even

parity */

bool getParity(unsigned int n)

{

bool parity = 0;

while (n)

{

parity = !parity;

n = n & (n - 1);

}

return parity;

}

/* Driver program to test getParity() */

int main()

{

unsigned int n = 7;

printf("Parity of no %d = %s", n,

(getParity(n)? "odd": "even"));

getchar();

return 0;

}

CODING BY:SONU BARNWAL CENTRAL UNIVERSITY OF BIHAR

User Avatar

Wiki User

12y ago

Still curious? Ask our experts.

Chat with our AI personalities

BeauBeau
You're doing better than you think!
Chat with Beau
JudyJudy
Simplicity is my specialty.
Chat with Judy
SteveSteve
Knowledge is a journey, you know? We'll get there.
Chat with Steve

Add your answer:

Earn +20 pts
Q: Write a program to implement parity bit checker?
Write your answer...
Submit
Still have questions?
magnify glass
imp