Java Bit Shift shift(int a, int b)

Here you can find the source of shift(int a, int b)

Description

shift

License

Open Source License

Declaration

public static int shift(int a, int b) 

Method Source Code

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

public class Main {
    public static int shift(int a, int b) {
        if ((0 < b) && (b < 32)) {
            return a << b;
        } else if ((-32 < b) && (b < 0)) {
            return a >> (-b);
        } else if (b == 0) {
            return a;
        } else if (b >= 32) {
            return 0;
        } else {/*from www . j av  a2  s . c o  m*/
            if (a > 0) {
                return 0;
            } else {
                return -1;
            }
        }
    }

    public static long shift(long a, int b) {
        if ((0 < b) && (b < 64)) {
            return a << b;
        } else if ((-64 < b) && (b < 0)) {
            return a >> (-b);
        } else if (b == 0) {
            return a;
        } else if (b >= 64) {
            return 0L;
        } else {
            if (a > 0) {
                return 0L;
            } else {
                return -1L;
            }
        }
    }
}

Related

  1. shift(int component, int shift)
  2. shift(int direction, long sq, int delta)
  3. shift(int length)
  4. shift(String string)