#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)){ ctr++; } } return ctr; } bool isEven(uint32_t data){ return !(data%2); }
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.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE