#include <stdio.h>
int isKthBitSet(int n, int k) {
// Write your code here
if(n & (1 << k)) {
return 1;
}
else {
return 0;
}
}
int main() {
int n, k;
scanf("%d %d", &n, &k);
printf("%d", isKthBitSet(n, k));
return 0;
}In C, bitwise operations allow direct manipulation of individual bits within a byte, word, or register. These operations are performed using the following operators:
Common bit-masking patterns:
reg |= (1 << n); // Set bit n
reg &= ~(1 << n); // Clear bit n
reg ^= (1 << n); // Toggle bit n
if (reg & (1 << n)) // Check if bit n is setThese operations are used to target and modify only specific bits, without disturbing others.
Input
8 3
Expected Output
1