Question bank › Bit Manipulation
Dsa Bit Manipulation Medium

Set Kth Bit

You are given an integer `num` and another integer `k`. Set the `k`-th bit of `num` to `1` (0-indexed). Print the modified number. Input: Two space-separated integers `num` (0 ≤ num ≤ 10^9) and `k` (0 ≤ k ≤ 30). Output: A single integer, which is the modified number after setting the k-th bit. Example: Input: 3 1 Output: 3 Explanation: The number 3 in binary is 011. Setting the 1st bit to 1 (it is already set) gives 011, which is still 3.

Key concepts

bit_manipulationbitwiseset

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.