In NXP Semiconductors embedded software, register updates are often done with bit masks. Given a 32-bit unsigned register value, write a function that sets the 5th bit and returns the updated register.
Assume bit positions are 0-indexed from the least significant bit, so the 5th bit means bit index 4.
reg representing a 32-bit unsigned register value.Example 1
reg = 0160b0000 becomes 0b10000.Example 2
reg = 181818 is 0b10010, and bit 4 is already set, so the value does not change.0 <= reg <= 2^32 - 1A C macro for this operation would conceptually use reg | (1U << 4). Implement the equivalent logic in Python.
reg = 0Output16WhyBinary `0` becomes `0b10000`, so the result is 16.reg = 18Output18Why18 is `0b10010`; bit 4 is already set, so OR with `0b10000` leaves it unchanged.reg = 3Output19Why3 is `0b00011`; setting bit 4 gives `0b10011`, which is 19.0 <= reg <= 4294967295The register is treated as a 32-bit unsigned valueBit positions are 0-indexed from the least significant bitThe solution should use bitwise operationsdef set_fifth_bit(reg):