DescriptionQ343
Q343FWASIC interview problem
Get, set, clear, and toggle one bit
TechniquesBitsMask
DifficultyEasy
TopicBit Manipulation
LanguageSystemVerilog
Requirements2 checkpoints
01
Problem
Implement helpers to read, set, clear, and toggle bit i of a 32-bit unsigned integer.
Example input and output
Use this case to check your interpretationInput
value = 8'b0010_1000, bit_index = 1Output
get=0, set=0010_1010, clear=0010_1000, toggle=0010_1010Explanation
Bit 1 starts clear, so the example visibly distinguishes setting and toggling it from reading or clearing it.
02
Requirements (2)
- Build the mask from an unsigned one.
- Assume i is in the range 0 through 31.
