List of usage examples for java.lang Long rotateLeft
public static long rotateLeft(long i, int distance)
From source file:Main.java
public static void main(String[] args) { long n = 64; n = Long.rotateLeft(n, 4); System.out.println(n); }
From source file:bits.MultiSyncPatternMatcher.java
/** * Processes two bits before checking sync processors for a match. *///from w w w. j av a 2s . c om public void receive(boolean bit1, boolean bit2) { mBits = Long.rotateLeft(mBits, 1); mBits &= mMask; if (bit1) { mBits += 1; } mBits = Long.rotateLeft(mBits, 1); mBits &= mMask; if (bit2) { mBits += 1; } for (ISyncProcessor processor : mSyncProcessors) { processor.checkSync(mBits); } }
From source file:bits.MultiSyncPatternMatcher.java
/** * Processes one bit before checking sync processors for a match. */// w w w .j a v a2 s. c om public void receive(boolean bit) { mBits = Long.rotateLeft(mBits, 1); mBits &= mMask; if (bit) { mBits += 1; } for (ISyncProcessor processor : mSyncProcessors) { processor.checkSync(mBits); } }
From source file:bits.BinaryMessage.java
/** * Returns the long 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/*from w ww .ja va 2 s .c o m*/ * @return - integer value of the bit array */ public long getLong(int[] bits) { if (bits.length > 64) { throw new IllegalArgumentException( "Overflow - must be 64 bits " + "or less to fit into a primitive long value"); } long value = 0; for (int index : bits) { value = Long.rotateLeft(value, 1); if (get(index)) { value++; } } return value; }
From source file:bits.BinaryMessage.java
/** * Returns the long 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. * /*from w w w. j a va 2 s. co m*/ * start < end: little endian interpretation * end < start: big endian interpretation * * @param start - MSB of the value * @param end - LSB of the value * * @return - long value of the bit range */ public long getLong(int start, int end) { if (Math.abs(end - start) > 64) { throw new IllegalArgumentException( "Overflow - must be 64 bits " + "or less to fit into a primitive long value"); } long value = 0; if (start < end) { for (int x = start; x <= end; x++) { value = Long.rotateLeft(value, 1); if (get(x)) { value++; } } } else { for (int x = end; x >= start; x--) { value = Long.rotateLeft(value, 1); if (get(x)) { value++; } } } return value; }
From source file:bits.BinaryMessage.java
/** * Loads the value into the buffer starting at the offset index, and * assuming that the value represents (width) number of bits. The MSB of * the value will be located at the offset and the LSB of the value will * be located at ( offset + width ).//from www .ja v a2 s .co m * * @param offset - starting bit index for the MSB of the value * @param width - representative bit width of the value * @param value - value to be loaded into the buffer */ public void load(int offset, int width, long value) { for (int x = 0; x < width; x++) { long mask = Long.rotateLeft(1, width - x - 1); if ((mask & value) == mask) { set(offset + x); } else { clear(offset + x); } } }