DescriptionQ721
Q721FWASIC interview problem
Check for a power of two
TechniquesBitsMask
DifficultyEasy
TopicBit Manipulation
LanguageSystemVerilog
Requirements3 checkpoints
01
Problem
Return 1 when an unsigned integer is a non-zero power of two.
Example input and output
Use this case to check your interpretationInput
value = 64 (0b0100_0000)Output
1 (power of two)Explanation
A nonzero power of two has one set bit, so value & (value - 1) is zero.
02
Requirements (3)
- Reject zero.
- Use a constant-time bit operation.
- Do not loop over every bit.
