We help IT Professionals succeed at work.
Get Started
Troubleshooting Question

Set Even Parity

Last Modified: 2020-11-24
Have I done the exercise right or is something wrong?
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>

uint32_t setEvenParity(uint32_t data);
uint8_t numberOfOnes(uint32_t data);
bool isEven(uint32_t data);

int main()
    printf("%d\n", setEvenParity(0));
    printf("%d\n", setEvenParity(1));
    printf("%d\n", setEvenParity(2));
    printf("%d\n", setEvenParity(3));
    printf("%d\n", setEvenParity(4));
    return 0;

uint32_t setEvenParity(uint32_t data){
    if(numberOfOnes == isEven(data)){
        return data || (0 << 31);
        return data || (1 << 31);

uint8_t numberOfOnes(uint32_t data){
    uint8_t ctr=0;
    for(int i=1;i<=32;i++){
        if(data & (1<<i)){
    return ctr;

bool isEven(uint32_t data){
    return !(data%2);

Watch Question
Top Expert 2015
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE