Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Bitwise Status Flag Extraction

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Bitwise Status Flag Extraction. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

An Analog Devices ADuCM3029 status register contains control and diagnostic bits. Implement a function that inverts only the bits selected by an inversion mask, preserves every other bit, and extracts named status flags from the original register value.

Formal Specification

Implement process_register(register_value, width, invert_mask, flag_masks).

  • register_value is a non-negative integer containing the register contents.
  • width is the register width in bits.
  • invert_mask identifies the bits to toggle. Bits outside this mask must remain unchanged.
  • flag_masks is a dictionary mapping flag names to nonzero bit masks.
  • Return a dictionary with:
    • inverted_value: the register value after toggling the selected bits.
    • flags: a dictionary mapping each flag name to True if any bit in its mask is set in the original register, otherwise False.

The result must be limited to the specified register width. Do not use string conversion or per-bit lists.

Constraints

  • 1 <= width <= 64
  • 0 <= register_value < 2^width
  • 0 <= invert_mask < 2^width
  • flag_masks contains at most 32 entries
  • Every flag mask is nonzero and fits within width bits

Function Signature

def process_register(register_value, width, invert_mask, flag_masks):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output