basics · intermediate · ~15 min
Test whether every masked bit is set.
Implement:
int has_all_flags(unsigned v, unsigned mask);
Return 1 if every bit set in mask is also set in v, else 0.
A flags value v and a mask.
1 if all mask bits are present in v.
An empty mask (0) is vacuously present -> 1.
#include <stddef.h>
/* Return 1 if every bit set in mask is also set in v (all flags present). */
int has_all_flags(unsigned v,unsigned mask){ (void)v;(void)mask; return 0; }
Testing v & mask != 0 (that is any flag, not all).
Superset v returns 1; a single missing bit returns 0.
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.