Java Array Shift shiftRightN(int[] x, int n)

Here you can find the source of shiftRightN(int[] x, int n)

Description

shift Right N

License

Open Source License

Declaration

static int shiftRightN(int[] x, int n) 

Method Source Code

//package com.java2s;

public class Main {
    static int shiftRightN(int[] x, int n) {
        //        int c = 0, nInv = 32 - n;
        //        for (int i = 0; i < 4; ++i)
        //        {
        //            int b = x[i];
        //            x[i] = (b >>> n) | c;
        //            c = b << nInv;
        //        }
        //        return c;

        int b = x[0], nInv = 32 - n;
        x[0] = b >>> n;//w w  w.  java  2s.  c om
        int c = b << nInv;
        b = x[1];
        x[1] = (b >>> n) | c;
        c = b << nInv;
        b = x[2];
        x[2] = (b >>> n) | c;
        c = b << nInv;
        b = x[3];
        x[3] = (b >>> n) | c;
        return b << nInv;
    }

    static int shiftRightN(int[] x, int n, int[] z) {
        //        int c = 0, nInv = 32 - n;
        //        for (int i = 0; i < 4; ++i)
        //        {
        //            int b = x[i];
        //            z[i] = (b >>> n) | c;
        //            c = b << nInv;
        //        }
        //        return c;

        int b = x[0], nInv = 32 - n;
        z[0] = b >>> n;
        int c = b << nInv;
        b = x[1];
        z[1] = (b >>> n) | c;
        c = b << nInv;
        b = x[2];
        z[2] = (b >>> n) | c;
        c = b << nInv;
        b = x[3];
        z[3] = (b >>> n) | c;
        return b << nInv;
    }
}

Related

  1. shiftRight(Object[] array, final int amount)
  2. shiftRight(T[] array)
  3. shiftRight2(T[] array, int to)
  4. shiftRightN(int[] block, int n)
  5. shiftRightN(int[] block, int n)
  6. shiftRightState(int[] state)
  7. shiftStringArray(String[] input)
  8. unshift(String[] array, String newElem)