Skip to the selected question
ASIC.FYI

ASIC Question Bank

1,000+ hardware interview questions
DescriptionQ343
Page ↗
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 interpretation
Input
value = 8'b0010_1000, bit_index = 1
Output
get=0, set=0010_1010, clear=0010_1000, toggle=0010_1010
Explanation

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.