0

If the shifting is not always the same, i.e I may have to use the same function to resize 2 or 4 characters, what would be a good way to circular shift the values of an array of bytes 2 positions * a parameter? This is what I have so far

for(int j=0; j<param; j++){
        if(j == 0){
            for(int i=0; i<myArray.length;i++){
                result[i] = (byte) (myArray[i]<<2); 
            }
        } else{
            for(int i=0; i<result.length;i++){
                if((result.length-i) > 2){
                    result[i] = (byte) (result[i]<<2);
                }
            }   
        }
    }

Summing up, I have to circular shift the values of myArray twice times param and return the result in the array 'result'. I don't get how to do this when the parameter 'param' is not fixed.

dLobatog
  • 1,751
  • 16
  • 17

1 Answers1

0

First: If possible, use java.util.BitSet for tasks like that.

I am not sure, but somehow BitSet itself does not have shift, but this source looks it implemented it.

aldrinleal
  • 3,559
  • 26
  • 33