Java Array Shift shiftRight(int[] x)

Here you can find the source of shiftRight(int[] x)

Description

shift Right

License

Open Source License

Declaration

static int shiftRight(int[] x) 

Method Source Code

//package com.java2s;

public class Main {
    static int shiftRight(int[] x) {
        //        int c = 0;
        //        for (int i = 0; i < 4; ++i)
        //        {
        //            int b = x[i];
        //            x[i] = (b >>> 1) | c;
        //            c = b << 31;
        //        }
        //        return c;

        int b = x[0];
        x[0] = b >>> 1;//from w  w  w .  j a  v a 2 s . co  m
        int c = b << 31;
        b = x[1];
        x[1] = (b >>> 1) | c;
        c = b << 31;
        b = x[2];
        x[2] = (b >>> 1) | c;
        c = b << 31;
        b = x[3];
        x[3] = (b >>> 1) | c;
        return b << 31;
    }

    static int shiftRight(int[] x, int[] z) {
        //      int c = 0;
        //      for (int i = 0; i < 4; ++i)
        //      {
        //          int b = x[i];
        //          z[i] = (b >>> 1) | c;
        //          c = b << 31;
        //      }
        //      return c;

        int b = x[0];
        z[0] = b >>> 1;
        int c = b << 31;
        b = x[1];
        z[1] = (b >>> 1) | c;
        c = b << 31;
        b = x[2];
        z[2] = (b >>> 1) | c;
        c = b << 31;
        b = x[3];
        z[3] = (b >>> 1) | c;
        return b << 31;
    }

    static long shiftRight(long[] x) {
        long b = x[0];
        x[0] = b >>> 1;
        long c = b << 63;
        b = x[1];
        x[1] = (b >>> 1) | c;
        return b << 63;
    }

    static long shiftRight(long[] x, long[] z) {
        long b = x[0];
        z[0] = b >>> 1;
        long c = b << 63;
        b = x[1];
        z[1] = (b >>> 1) | c;
        return b << 63;
    }
}

Related

  1. shiftOffsets(int[] offsets, int changeOffset, int oldLength, int newLength)
  2. shiftOnRow(double[][] d, int q)
  3. shiftRight(byte[] block)
  4. shiftRight(byte[] x)
  5. shiftRight(int[] result, int[] vec, int shift)
  6. shiftRight(Object[] array, final int amount)
  7. shiftRight(T[] array)
  8. shiftRight2(T[] array, int to)
  9. shiftRightN(int[] block, int n)