Geeksforgeeks

Error

×

Leaderboard

Showing:

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

@Ibrahim Nash | 5725 |

@blackshadows | 5685 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4908 |

@saiujwal13083 | 4156 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3511 |

@sushant_a | 3453 |

@KshamaGupta | 3318 |

@the_coder95 | 3302 |

Complete Leaderboard | |

Handle | Score |

@avaiesshaik782 | 786 |

@arpitsatnalika | 777 |

@tujhekya | 602 |

@prakharxyz | 601 |

@code_it_ | 591 |

@iamronak | 505 |

@imnm | 500 |

@pradeepkumarjad | 488 |

@satyam0460 | 481 |

@nitesha125 | 480 |

@Rahul Jadhav 1 | 466 |

Complete Leaderboard |

Given an integer **N** and an integer **D**, you are required to write a program to **rotate the binary representation** of the integer **N by D **digits to the **left **as well as **right **and print the **results **in **decimal values** after each of the rotation.

**Note**: Integer N is stored using **16 bits**. i.e. 12 will be stored as 0000.....001100.

**Input**:

First line of input contains a single integer **T** which denotes the number of test cases. Each test case contains two space separated integers **N** and **D** where N denotes the number to be rotated and D denotes the number of digits by which the number is required to be rotated.

**Output:**

For each testcase, in a new line, print the value of number N after rotating it to **left **by D digits in **one line,** and **second line** prints the value of number N after rotating it to the **right **by D digits.

**Constraints:**

1 <= T <= 100

1 <= N < 2^{16}

1 <= D <= 10^{5}

**Example:
Input:**

2

229 3

28 2

1832

40988

112

7

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
Rotate Bits

...

Please choose 'ReadOnlyMode' if you needn't to 'Edit' the problem e.g. viewing OJ's solution, TestCase Files (TCFs), TimeLimit etc.