List of usage examples for java.lang Integer rotateLeft
public static int rotateLeft(int i, int distance)
From source file:bits.BinaryMessage.java
/** * Returns the byte 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. jav a 2 s . c om*/ * @return - byte value of the bit array */ public byte getByte(int[] bits) { if (bits.length != 8) { throw new IllegalArgumentException("Invalid - there must be 8" + "indexes to form a proper byte"); } int value = 0; for (int index : bits) { value = Integer.rotateLeft(value, 1); if (get(index)) { value++; } } return (byte) (value & 0xFF); }
From source file:bits.BinaryMessage.java
/** * Returns the int value represented by the bit range. This method will * parse the bits in big endian or little endian format. The start value * represents the MSB and the end value represents the LSB of the value. * // ww w . ja va 2 s . c om * start < end: little endian interpretation * end < start: big endian interpretation * * @param start - MSB of the value * @param end - LSB of the value * * @return - int value of the bit range */ public int getInt(int start, int end) { if (Math.abs(end - start) > 32) { throw new IllegalArgumentException( "Overflow - must be 32 bits " + "or less to fit into a primitive integer value"); } int value = 0; if (start < end) { for (int x = start; x <= end; x++) { value = Integer.rotateLeft(value, 1); if (get(x)) { value++; ; } } } else { for (int x = end; x >= start; x--) { value = Integer.rotateLeft(value, 1); if (get(x)) { value++; ; } } } return value; }
From source file:org.apache.tinkerpop.gremlin.process.traversal.step.util.Parameters.java
public int hashCode() { int result = 1; for (final Map.Entry<Object, List<Object>> entry : this.parameters.entrySet()) { result ^= entry.getKey().hashCode(); for (final Object value : entry.getValue()) { result ^= Integer.rotateLeft(value.hashCode(), entry.getKey().hashCode()); }// w w w.j a va2s. c o m } return result; }