Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 5761 |

@blackshadows | 5715 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4944 |

@saiujwal13083 | 4506 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3516 |

@sushant_a | 3459 |

@verma_ji | 3341 |

@KshamaGupta | 3318 |

Complete Leaderboard | |

Handle | Score |

@aroranayan999 | 1115 |

@bt8816103042 | 739 |

@SherlockHolmes3 | 447 |

@codeantik | 441 |

@SHOAIBVIJAPURE | 430 |

@shalinibhataniya1097 | 408 |

@ShamaKhan1 | 392 |

@neverevergiveup | 381 |

@amrutakashikar2 | 355 |

@mahlawatep | 353 |

@murarry3625 | 352 |

Complete Leaderboard |

Given a number **N **and a bit number **K**, check if **K ^{th}** bit of N is

**Input**: N = 4, K = 0
**Output**: false
**Explanation**: Binary representation of 4 is 100,
in which 0^{th} bit from LSB is not set.
So, return false.

**Example 2:**

**Input**: N = 4, K = 2
**Output**: true
**Explanation**: Binary representation of 4 is 100,
in which 2^{nd} bit from LSB is set.
So, return true.

**Example 3:**

**Input**: N = 500, K = 3
**Output**: false
**Explanation**: Binary representation of 500 is
111110100, in which 3rd bit from LSB is not set.
So, return false.

**Your Task: **This is a function problem. You only need to complete the **function checkKthbit **that takes **n and k as parameters** and **returns **either **true **(if kth bit is set) or **false**(if kth bit is not set).

**Expected Time Complexity:** O(1).

**Expected Auxiliary Space:** O(1).

**Constraints:**

1 ≤ N ≤ 10^{9}

0 ≤ K ≤ floor(log_{2}(N) + 1)

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Check whether K-th bit is set or not

...