Dsa
Bit Manipulation
Easy
Toggle Bits
Write a program that takes an integer N and an integer K and toggles the K-th bit of N. The bit positions are zero-indexed. Print the result.
Input format:
- A single line containing two integers N (0 <= N <= 10^9) and K (0 <= K <= 31).
Output format:
- The resulting integer after toggling the K-th bit.
Example:
Input:
5 1
Output:
7
(The binary representation of 5 is '101'. Toggling the 1st bit gives '111', which is 7.)
Key concepts
bit_manipulationbitwise_operations
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now