Java Array Multiply multiplyP(int[] x)

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

Description

multiply P

License

Open Source License

Declaration

static void multiplyP(int[] x) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    private static final int E1 = 0xe1000000;

    static void multiplyP(int[] x) {
        if (shiftRight(x) != 0) {
            x[0] ^= E1;/*from w w  w  .  j  av  a 2 s  . c o m*/
        }
    }

    static void multiplyP(int[] x, int[] y) {
        if (shiftRight(x, y) != 0) {
            y[0] ^= E1;
        }
    }

    static byte shiftRight(byte[] x) {
        //        int c = 0;
        //        for (int i = 0; i < 16; ++i)
        //        {
        //            int b = x[i] & 0xff;
        //            x[i] = (byte)((b >>> 1) | c);
        //            c = (b & 1) << 7;
        //        }
        //        return (byte)c;

        int i = 0, c = 0;
        do {
            int b = x[i] & 0xff;
            x[i++] = (byte) ((b >>> 1) | c);
            c = (b & 1) << 7;
            b = x[i] & 0xff;
            x[i++] = (byte) ((b >>> 1) | c);
            c = (b & 1) << 7;
            b = x[i] & 0xff;
            x[i++] = (byte) ((b >>> 1) | c);
            c = (b & 1) << 7;
            b = x[i] & 0xff;
            x[i++] = (byte) ((b >>> 1) | c);
            c = (b & 1) << 7;
        } while (i < 16);
        return (byte) c;
    }

    static byte shiftRight(byte[] x, byte[] z) {
        //        int c = 0;
        //        for (int i = 0; i < 16; ++i)
        //        {
        //            int b = x[i] & 0xff;
        //            z[i] = (byte) ((b >>> 1) | c);
        //            c = (b & 1) << 7;
        //        }
        //        return (byte) c;

        int i = 0, c = 0;
        do {
            int b = x[i] & 0xff;
            z[i++] = (byte) ((b >>> 1) | c);
            c = (b & 1) << 7;
            b = x[i] & 0xff;
            z[i++] = (byte) ((b >>> 1) | c);
            c = (b & 1) << 7;
            b = x[i] & 0xff;
            z[i++] = (byte) ((b >>> 1) | c);
            c = (b & 1) << 7;
            b = x[i] & 0xff;
            z[i++] = (byte) ((b >>> 1) | c);
            c = (b & 1) << 7;
        } while (i < 16);
        return (byte) c;
    }

    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;
        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. multiplyElementwise(double[] a, int[] b)
  2. multiplyHarmonics(float[] powerSpectrumInOut, int nHarmonics)
  3. multiplyInPlace(double[] img, double val)
  4. multiplyInto(double[] out, double[] a, double[] b)
  5. multiplyP(int[] x)
  6. multiplyP(int[] x)
  7. multiplyP(int[] x)
  8. multiplyP8(int[] x)
  9. multiplyP8(int[] x)