Your question is Bit Manipulation Macro. 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.
Autonomous Solutions firmware uses 32-bit registers to represent controller flags. Implement a Python function that models a C-style bit macro by setting, clearing, or toggling exactly one bit while preserving every other bit.
Implement update_register(register, bit, operation).
register is an integer representing a 32-bit unsigned register.bit is an integer from 0 through 31, where bit 0 is the least significant bit.operation is one of the strings "set", "clear", or "toggle".Use a bit mask formed from 1 << bit:
set turns the selected bit on.clear turns the selected bit off.toggle reverses the selected bit.The input register is valid and already fits within 32 bits. The operation is also valid.
def update_register(register, bit, operation):