Skip to the selected question
ASIC.FYI

ASIC Question Bank

1,000+ hardware interview questions
DescriptionQ721
Page ↗
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 interpretation
Input
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.