This problem has a simple solution given the following:
Suppose that k is the value we want to shift, it is a 32-bit integer and we want to shift it n times to the right.
1. Regular shifting usually zeroes out values that are shifted out of the original, in both directions.
e.g. 000101 >> 1 = 000010 (or 5 shifted 1 times to the right gives 2)
2. We want the zeroed out values to be appended in the same order at the beginning of the resulting value, thus, we can shift them left a number of times that is equal to the original value's bitsize minus the number of shifts we want to do.
The code is:
public int bitWiseShift(int k, int shifts){
if(shifts == 0) return k;
return k >> shifts | k << 32 - shifts;
}