Q120FreeSystemVerilog
Clear the lowest set bit
Interview prompt
Question
Return x with its least-significant 1 bit cleared.
Candidate starting point
Implementation scaffold
function automatic int unsigned clear_lowest_one(int unsigned x);
// TODO: implement.
endfunctionReviewed example
Trace one case
Input
value = 8'b1011_0000Expected output
8'b1010_0000ANDing with value - 1 clears only the lowest set bit, which is bit 4 here.
What to cover
Requirements
- Return zero when x is zero.
- Use one arithmetic and one bitwise operation.
