In embedded code for Google Pixel device drivers, low-level register access often requires changing individual bits without affecting the rest of the register. Implement a function that processes a sequence of bit operations on an unsigned register value.
Write a function that takes an initial integer register, a register width width, and a list of operations. Each operation is one of:
("set", bit)("clear", bit)("toggle", bit)("read", bit)For each read operation, record whether the target bit is 0 or 1. Return the final register value and the list of read results.
Bit positions are 0-indexed from the least significant bit. All updates must stay within the lower width bits.
register (int), width (int), operations (list of [op, bit] pairs)[final_register, read_results] where read_results is a list of integers 0 or 1set, clear, toggle, readdef process_register_ops(register, width, operations):
You are practicing as a guest. Sign up free to run your code against the sample data. Your draft stays right here.