Count Error Flags in Status Word

Easy C Memory
Solve this problem

Write a C function to count the number of set error flags in a 32-bit status register. Only bits defined in mask should be counted.

Constraints

  • Function prototype: int count_errors(uint32_t reg, uint32_t mask).
  • Count only masked bits.
  • Use bitwise ops.
  • Return integer count.
Starter codeC
1#include <stdint.h>2int count_errors(uint32_t reg, uint32_t mask);