Associated Course(s):
Must Do Interview Preparation

Given a number **N** and a value **K**. From the right, set the Kth bit in the binary representation of N. The position of LSB(or last bit) is **0**, second last bit is 1 and so on. Also, 0 <= K < X, where X is the number of bits in the binary representation of N.

**Input:**

First line of input contains a single integer **T**, which denotes the number of test cases. T test cases follows. First line of each testcase contains two space separated integers N and K.

**Output:**

For each test case, print the new number after setting the Kth bit of N.

**Constraints:**

1 <= T <= 100

1 <= N <= 1000

**Example:
Input:**

2

10 2

15 3

**Output:**

14

15

**Explanation:
Testcase 1:** Binary representation of the given number 10 is: 1 0 1 0, number of bits in the binary reprsentation is 4. Thus 2nd bit from right is 0. The number after changing this bit to 1 is: 14(1 1 1 0).

Author: harsh.agarwal0

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

hardikJain5 | 110 |

CodeBuddy | 107 |

Akkki111 | 100 |

saurabhgrade1 | 98 |

WrongAnswer | 80 |

KshatriyaYash | 1932 |

nikhil_sojan | 1374 |

lonecoder | 1236 |

SumitSingh27 | 1103 |

mazumderrohit8 | 1095 |

blackshadows | 5327 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4566 |

Quandray | 4444 |

Login to report an issue on this page.