Question bank › Bit Manipulation
Dsa Bit Manipulation Medium

Kth Bit Activation

Write a function that takes an integer n and an integer k. Your task is to find and return the integer generated by activating the k-th bit of the binary representation of n. If the k-th bit is already set, return n itself. If not, return the modified integer. Example: Input: 5 2 Output: 7 Explanation: The binary representation of 5 is 101. Activating the 2nd bit (counting from 0) results in 111, which is 7.

Key concepts

bit manipulationbit activationbit counting

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
Part of Praxari's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.