Package autumn.util
Class Bitwise
java.lang.Object
autumn.util.Bitwise
This class provides bitwise manipulations, since the language does not have bitwise operators.
Warning: This class is still under development.
- Author:
- Mackenzie High
-
Method Summary
Modifier and TypeMethodDescriptionstatic long
and
(long left, long right) This method performs a bitwise logical-AND.static boolean
get
(long bits, int index) This method gets a single bit.static long
not
(long bits) This method performs a bitwise negation.static long
or
(long left, long right) This method performs a bitwise logical-OR.static long
set
(long bits, int index, boolean value) This method sets a single bit.static long
shiftLeft
(long bits, int count) This method performs a bitwise left-shift operation.static long
shiftRight
(long bits, int count) This method performs a bitwise right-shift operation.static long
shiftRightUnsigned
(long bits, int count) This method performs a bitwise unsigned-right-shift operation.static long
xor
(long left, long right) This method performs a bitwise logical-XOR.
-
Method Details
-
shiftLeft
public static long shiftLeft(long bits, int count) This method performs a bitwise left-shift operation.- Parameters:
bits
- contains the bits to shift.count
- is the distance of the shift.- Returns:
- the bits shifted by the specified distance.
-
shiftRight
public static long shiftRight(long bits, int count) This method performs a bitwise right-shift operation.- Parameters:
bits
- contains the bits to shift.count
- is the distance of the shift.- Returns:
- the bits shifted by the specified distance.
-
shiftRightUnsigned
public static long shiftRightUnsigned(long bits, int count) This method performs a bitwise unsigned-right-shift operation.- Parameters:
bits
- contains the bits to shift.count
- is the distance of the shift.- Returns:
- the bits shifted by the specified distance.
-
set
public static long set(long bits, int index, boolean value) This method sets a single bit.- Parameters:
bits
- contains the bit to set.index
- is the index of the bit to set.value
- the new value of the bit.- Returns:
- the modified version of bits.
-
get
public static boolean get(long bits, int index) This method gets a single bit.- Parameters:
bits
- contains the bit to get.index
- is the index of the bit to get.- Returns:
- the selected bit.
-
not
public static long not(long bits) This method performs a bitwise negation.- Parameters:
bits
- are the bits to negate.- Returns:
- the negated bits.
-
and
public static long and(long left, long right) This method performs a bitwise logical-AND.- Parameters:
left
- is the left operand.left
- is the right operand.- Returns:
- the result.
-
or
public static long or(long left, long right) This method performs a bitwise logical-OR.- Parameters:
left
- is the left operand.left
- is the right operand.- Returns:
- the result.
-
xor
public static long xor(long left, long right) This method performs a bitwise logical-XOR.- Parameters:
left
- is the left operand.left
- is the right operand.- Returns:
- the result.
-