Set Bit

Easy Bitwise Operations
Solve in Playground →

Problem Statement

Write a C program to set (make 1) the K-th bit of a given number N.

Input Format

Two space-separated integers N and K.

Output Format

Print the updated integer value after setting the K-th bit.

Constraints

0 <= N <= 1000000, 0 <= K <= 31

Sample Input

4 1

Sample Output

6

Explanation

Binary of 4 is 100. Setting the 1st bit gives 110, which is 6 in decimal.

Starter Code

#include <stdio.h>

int main() {
    int n, k;
    if (scanf("%d %d", &n, &k) == 2) {
        // Write your code here
    }
    return 0;
}

Limits

  • Time Limit: 1s
  • Memory Limit: 256MB

Embedded C Programming

Updated: March 15, 2026
Intermediate

Embedded systems rely on efficient low-level programming to interact directly with hardware. In this course, you will learn how to write practical Embedded C programs used in real microcontroller-based systems. Rather than focusing only on theory, this course follows a practice-driven approach. Each lesson includes hands-on coding exercises that simulate real firmware development tasks used