Cyclic shifts

4

87 votes
Basic Programming, Bit Manipulation, C++
Problem

You are given a number N represented as a binary representation of X=16 bits. You are also given a number m and a character c (L or R).

Determine a number M that is generated after cyclically shifting the binary representation of N by m positions either left if c=L or right is c=R.

Input format 

  1. The first line contains an integer T representing the number of queries.
  2. The next T lines contain N m c as mentioned in the problem statement.

Output format

Print T integers in a separate line representing the answer to each query.

Constraints
1T1e41N655351m15 
 

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

For first case :  N in binary is 0001 1110 1100 1001 and shifting it left by 5 position, it becomes 1101 1001 0010 0011 which in decimal system is 55587

For second case : N in binary is 0001 1110 1100 1001 and shifted 3 position to right it becomes 0010 0011 1101 1001 which in decimal system is 9177

Editor Image

?