Skip to question
asic.fyi
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
asic.fyi/Interview questions/Get, set, clear, and toggle one bit

Hardware interview practice

Get, set, clear, and toggle one bit

EasyBit ManipulationSystemVerilog

Implement helpers to read, set, clear, and toggle bit i of a 32-bit unsigned integer.

Try it in the question bankReason first. Then compare.

Keep this exact question selected while you check your answer and review the full solution.

Practice this question →
Reviewed example

Work through one case

Input
value = 8'b0010_1000, bit_index = 1
Expected output
get=0, set=0010_1010, clear=0010_1000, toggle=0010_1010

Bit 1 starts clear, so the example visibly distinguishes setting and toggling it from reading or clearing it.

What to cover

Requirements

  1. Build the mask from an unsigned one.
  2. Assume i is in the range 0 through 31.
Continue practicing

Related questions

Bit ManipulationCheck for a power of two→Bit ManipulationClear the lowest set bit→
asic.fyi · Learn silicon end to end.info@asic.fyi