Example usage for java.lang Integer rotateLeft

List of usage examples for java.lang Integer rotateLeft

Introduction

In this page you can find the example usage for java.lang Integer rotateLeft.

Prototype

public static int rotateLeft(int i, int distance) 

Source Link

Document

Returns the value obtained by rotating the two's complement binary representation of the specified int value left by the specified number of bits.

Usage

From source file:Main.java

public static void main(String[] args) {

    System.out.println(Integer.rotateLeft(10, 2));

}

From source file:Bits.java

public static void main(String args[]) {
    int n = 170; // 10101010 
    System.out.println("Value in binary: 10101010");

    System.out.println("Number of one bits: " + Integer.bitCount(n));

    System.out.println("Highest one bit: " + Integer.highestOneBit(n));

    System.out.println("Lowest one bit: " + Integer.lowestOneBit(n));

    System.out.println("Number of leading zeros : " + Integer.numberOfLeadingZeros(n));

    System.out.println("Number of trailing zeros : " + Integer.numberOfTrailingZeros(n));

    System.out.println("\nBeginning with the value 1, " + "rotate left 16 times.");
    n = 1;/*from w  w w  . j  a  va2s . com*/
    for (int i = 0; i < 16; i++) {
        n = Integer.rotateLeft(n, 1);
        System.out.println(n);
    }
}

From source file:MainClass.java

public static void main(String args[]) throws IOException {
    int n = 170; // 10101010

    System.out.println("Value in binary: 10101010");

    System.out.println("Number of one bits: " + Integer.bitCount(n));

    System.out.println("Highest one bit: " + Integer.highestOneBit(n));

    System.out.println("Lowest one bit: " + Integer.lowestOneBit(n));

    System.out.println("Number of leading zeros : " + Integer.numberOfLeadingZeros(n));

    System.out.println("Number of trailing zeros : " + Integer.numberOfTrailingZeros(n));

    System.out.println("\nBeginning with the value 1, " + "rotate left 16 times.");
    n = 1;/*from  w  w  w . j ava 2  s.com*/
    for (int i = 0; i < 16; i++) {
        n = Integer.rotateLeft(n, 1);
        System.out.println(n);
    }

}

From source file:Main.java

public static byte[] CF(byte[] vi, byte[] bi) throws Exception {
    int a, b, c, d, e, f, g, h;
    a = toInteger(vi, 0);/*  www.  j  ava2 s. com*/
    b = toInteger(vi, 1);
    c = toInteger(vi, 2);
    d = toInteger(vi, 3);
    e = toInteger(vi, 4);
    f = toInteger(vi, 5);
    g = toInteger(vi, 6);
    h = toInteger(vi, 7);

    int[] w = new int[68];
    int[] w1 = new int[64];
    for (int i = 0; i < 16; i++) {
        w[i] = toInteger(bi, i);
    }
    for (int j = 16; j < 68; j++) {
        w[j] = P1(w[j - 16] ^ w[j - 9] ^ Integer.rotateLeft(w[j - 3], 15)) ^ Integer.rotateLeft(w[j - 13], 7)
                ^ w[j - 6];
    }
    for (int j = 0; j < 64; j++) {
        w1[j] = w[j] ^ w[j + 4];
    }
    // printIntArray(w, 8);
    // printIntArray(w1, 8);
    int ss1, ss2, tt1, tt2;
    for (int j = 0; j < 64; j++) {
        ss1 = Integer.rotateLeft(Integer.rotateLeft(a, 12) + e + Integer.rotateLeft(T(j), j), 7);
        ss2 = ss1 ^ Integer.rotateLeft(a, 12);
        tt1 = FF(a, b, c, j) + d + ss2 + w1[j];
        tt2 = GG(e, f, g, j) + h + ss1 + w[j];
        d = c;
        c = Integer.rotateLeft(b, 9);
        b = a;
        a = tt1;
        h = g;
        g = Integer.rotateLeft(f, 19);
        f = e;
        e = P0(tt2);
    }
    byte[] v = toByteArray(a, b, c, d, e, f, g, h);
    for (int i = 0; i < v.length; i++) {
        v[i] = (byte) (v[i] ^ vi[i]);
    }
    return v;
}

From source file:JenkinsHashFunction.java

private static long rot(long val, int pos) {
    return ((Integer.rotateLeft((int) (val & INT_MASK), pos)) & INT_MASK);
}

From source file:Main.java

static void scaleHalf(IntBuffer in, int w, int h, IntBuffer out, int rotate) {
    for (int i = 0; i < w / 2; ++i) {
        for (int j = 0; j < h / 2; ++j) {
            int k = w * 2 * j + 2 * i;
            int pixel00 = in.get(k);
            int pixel01 = in.get(k + 1);
            int pixel10 = in.get(k + w);
            int pixel11 = in.get(k + w + 1);

            if (rotate != 0) {
                pixel00 = Integer.rotateLeft(pixel00, rotate);
                pixel01 = Integer.rotateLeft(pixel01, rotate);
                pixel10 = Integer.rotateLeft(pixel10, rotate);
                pixel11 = Integer.rotateLeft(pixel11, rotate);
            }/*  w w w  .j a va  2s .c  om*/

            int pixel = average4RGBA(pixel00, pixel01, pixel10, pixel11);

            if (rotate != 0) {
                pixel = Integer.rotateRight(pixel, rotate);
            }

            out.put(w / 2 * j + i, pixel);
        }
    }
}

From source file:Main.java

public static Integer P1(Integer x) throws Exception {
    return Integer.valueOf(
            x.intValue() ^ Integer.rotateLeft(x.intValue(), 15) ^ Integer.rotateLeft(x.intValue(), 23));
}

From source file:Main.java

public static Integer P0(Integer x) throws Exception {
    return Integer
            .valueOf(x.intValue() ^ Integer.rotateLeft(x.intValue(), 9) ^ Integer.rotateLeft(x.intValue(), 17));
}

From source file:JenkinsHash.java

private static long rot(final long val, final int pos) {
    return ((Integer.rotateLeft((int) (val & INT_MASK), pos)) & INT_MASK);
}

From source file:bits.BinaryMessage.java

/**
 * Returns the integer value represented by the bit array
 * @param bits - an array of bit positions that will be treated as if they
 *          were contiguous bits, with index 0 being the MSB and index
 *          length - 1 being the LSB//  w  w w  . j  a v a  2 s . c o  m
 * @return - integer value of the bit array
 */
public int getInt(int[] bits) {
    if (bits.length > 32) {
        throw new IllegalArgumentException(
                "Overflow - must be 32 bits " + "or less to fit into a primitive integer value");
    }

    int value = 0;

    for (int index : bits) {
        value = Integer.rotateLeft(value, 1);

        if (get(index)) {
            value++;
        }
    }

    return value;
}