Java Bit Shift shift(int direction, long sq, int delta)

Here you can find the source of shift(int direction, long sq, int delta)

Description

shift

License

LGPL

Declaration

public static long shift(int direction, long sq, int delta) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

public class Main {
    private static long[] SHIFT_MASKS = new long[8];
    private static final int[] DIRECTION_SHIFTS = new int[] { 8, 9, 1, -7, -8, -9, -1, 7 };

    public static long shift(int direction, long sq, int delta) {
        long result = sq;
        for (int i = 0; i < delta; i++) {
            result = shift(direction, result);
        }/*w  ww  .ja  v a2 s .  c o m*/
        return result;
    }

    public static long shift(int direction, long sq) {
        int shift = DIRECTION_SHIFTS[direction];
        if (shift < 0)
            return (sq >>> (-shift)) & SHIFT_MASKS[direction];
        else
            return (sq << shift) & SHIFT_MASKS[direction];
    }
}

Related

  1. shift(int a, int b)
  2. shift(int component, int shift)
  3. shift(int length)
  4. shift(String string)
  5. shiftBits(byte b)
  6. shiftByte(byte n, short shift)