Class BitShiftUtil
java.lang.Object
com.seibel.distanthorizons.coreapi.util.BitShiftUtil
A list of helper methods to make code easier to read.
Specifically written because bit shifts short circuit James' brain.
Specifically written because bit shifts short circuit James' brain.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic int
divideByPowerOfTwo
(int value, int power) Equivalent to:
value >> power,
value / 2^power
Note: value / 2^power isn't identical for negative valuesstatic long
divideByPowerOfTwo
(long value, long power) seedivideByPowerOfTwo(int, int)
for documentationstatic int
half
(int value) Equivalent to:
value >> 1,
value / 2
Note: value / 2 isn't identical for negative valuesstatic long
half
(long value) seehalf(int)
for documentationstatic int
pow
(int value, int power) Equivalent to:
value << power,
value^power,
Math.pow(value, power)
Note: Math.pow() isn't identical for large values where bits would be lost in the shift, however for medium to small values they function the same.static long
pow
(long value, long power) seepow(int, int)
for documentationstatic int
powerOfTwo
(int value) Equivalent to:
1 << value,
2^value,
Math.pow(2, value)
Note: Math.pow() isn't identical for large values where bits would be lost in the shift, however for medium to small values they function the same.static long
powerOfTwo
(long value) seepowerOfTwo(int)
for documentationstatic int
square
(int value) Equivalent to:
value << 1,
value^2,
Math.pow(value, 2)
Note: Math.pow() isn't identical for large values where bits would be lost in the shift, however for medium to small values they function the same.static long
square
(long value) seesquare(int)
for documentation
-
Constructor Details
-
BitShiftUtil
public BitShiftUtil()
-
-
Method Details
-
powerOfTwo
public static int powerOfTwo(int value) Equivalent to:
1 << value,
2^value,
Math.pow(2, value)
Note: Math.pow() isn't identical for large values where bits would be lost in the shift, however for medium to small values they function the same.
Can also be used to replace bit shifts in the format:
multiplier << value;
multiplier * powerOfTwo(value); -
powerOfTwo
public static long powerOfTwo(long value) seepowerOfTwo(int)
for documentation -
half
public static int half(int value) Equivalent to:
value >> 1,
value / 2
Note: value / 2 isn't identical for negative values -
half
public static long half(long value) seehalf(int)
for documentation -
divideByPowerOfTwo
public static int divideByPowerOfTwo(int value, int power) Equivalent to:
value >> power,
value / 2^power
Note: value / 2^power isn't identical for negative values -
divideByPowerOfTwo
public static long divideByPowerOfTwo(long value, long power) seedivideByPowerOfTwo(int, int)
for documentation -
square
public static int square(int value) Equivalent to:
value << 1,
value^2,
Math.pow(value, 2)
Note: Math.pow() isn't identical for large values where bits would be lost in the shift, however for medium to small values they function the same. -
square
public static long square(long value) seesquare(int)
for documentation -
pow
public static int pow(int value, int power) Equivalent to:
value << power,
value^power,
Math.pow(value, power)
Note: Math.pow() isn't identical for large values where bits would be lost in the shift, however for medium to small values they function the same. -
pow
public static long pow(long value, long power) seepow(int, int)
for documentation
-