#C8271. Flip the Kth Bit
Flip the Kth Bit
Flip the Kth Bit
You are given two integers, N and K. Your task is to flip the Kth bit of N and output the new number.
Bit positions are indexed starting from 0 from the right. Flipping a bit means changing a 0 to a 1 or a 1 to a 0. Mathematically, the operation can be represented using the XOR operator as follows:
$$N \oplus (1 \ll K)$$
where \(1 \ll K\) denotes the left shift of 1 by K positions.
inputFormat
The input consists of a single line containing two integers separated by a space:
- N: a non-negative integer.
- K: an integer representing the bit position (0-indexed from the right).
You should read the input from stdin
.
outputFormat
Output a single integer which is the result of flipping the Kth bit of N. The output should be written to stdout
.
The result is computed as $$N \oplus (1 \ll K)$$.
## sample29 1
31