Rotate Bits
Submissions: 6511   Accuracy:


  Difficulty: Basic   Marks: 1

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.

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.

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.

1 <= T <= 100
1 <= N <  216
1 <= D <= 105


229 3
28 2

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Harsh Agarwal
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.

Need help with your code? Please use, generate link and share the link here.

to report an issue on this page.