#K45212. Modify Byte
Modify Byte
Modify Byte
You are given an 8-bit byte represented by an integer a (where \(0 \le a \le 255\)). You are also given a sequence of instructions. Each instruction consists of a pair \((i, v)\) where i is the bit position (0-indexed from the right, with \(0 \le i \le 7\)) and \(v\) is the new value for that bit (either 0 or 1).
Your task is to modify the given byte by applying all the instructions in order. To set the bit, you may use the operation \(a = a \mid (1 \ll i)\). To clear the bit, use \(a = a \& \sim(1 \ll i)\). After processing all instructions, output the modified byte as an integer.
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains an integer representing the initial byte value.
- The second line contains an integer \(n\) representing the number of instructions.
- The following \(n\) lines each contain two space-separated integers: the bit position \(i\) (with \(0 \le i \le 7\)) and the new bit value \(v\) (either 0 or 1).
outputFormat
Output a single integer to standard output (stdout): the modified byte after applying all instructions.## sample
170
0
170