basics · beginner · ~15 min
Use the x & -x idiom to isolate the lowest set bit.
Implement unsigned lowest_set_bit(unsigned x) returning the value of the least-significant set bit of x (e.g. 12 -> 4). Return 0 when x is 0.
unsigned lowest_set_bit(unsigned x) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.