Package org.esa.snap.core.util
Class BitSetter
java.lang.Object
org.esa.snap.core.util.BitSetter
Static function to manipulate bits inside an int or long.
- Since:
- 4.1
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
isFlagSet
(int flags, int bitIndex) Tests if a flag with the given index is set in a 32-bit collection of flags.static boolean
isFlagSet
(long flags, int bitIndex) Tests if a flag with the given index is set in a 64-bit collection of flags.static int
setFlag
(int flags, int bitIndex) Sets a flag with the given index in a 32-bit collection of flags.static int
setFlag
(int flags, int bitIndex, boolean cond) Sets a flag with the given index in a 32-bit collection of flags if a given condition istrue
.static long
setFlag
(long flags, int bitIndex) Sets a flag with the given index in a 64-bit collection of flags.static long
setFlag
(long flags, int bitIndex, boolean cond) Sets a flag with the given index in a 64-bit collection of flags if a given condition istrue
.
-
Constructor Details
-
BitSetter
public BitSetter()
-
-
Method Details
-
isFlagSet
public static boolean isFlagSet(int flags, int bitIndex) Tests if a flag with the given index is set in a 32-bit collection of flags.- Parameters:
flags
- a collection of a maximum of 32 flagsbitIndex
- the zero-based index of the flag to be tested- Returns:
true
if the flag is set
-
isFlagSet
public static boolean isFlagSet(long flags, int bitIndex) Tests if a flag with the given index is set in a 64-bit collection of flags.- Parameters:
flags
- a collection of a maximum of 64 flagsbitIndex
- the zero-based index of the flag to be tested- Returns:
true
if the flag is set
-
setFlag
public static int setFlag(int flags, int bitIndex) Sets a flag with the given index in a 32-bit collection of flags.- Parameters:
flags
- a collection of a maximum of 32 flagsbitIndex
- the zero-based index of the flag to be set- Returns:
- the collection of flags with the given flag set
-
setFlag
public static long setFlag(long flags, int bitIndex) Sets a flag with the given index in a 64-bit collection of flags.- Parameters:
flags
- a collection of a maximum of 64 flagsbitIndex
- the zero-based index of the flag to be set- Returns:
- the collection of flags with the given flag set
-
setFlag
public static int setFlag(int flags, int bitIndex, boolean cond) Sets a flag with the given index in a 32-bit collection of flags if a given condition istrue
.- Parameters:
flags
- a collection of a maximum of 32 flagsbitIndex
- the zero-based index of the flag to be setcond
- the condition- Returns:
- the collection of flags with the given flag possibly set
-
setFlag
public static long setFlag(long flags, int bitIndex, boolean cond) Sets a flag with the given index in a 64-bit collection of flags if a given condition istrue
.- Parameters:
flags
- a collection of a maximum of 64 flagsbitIndex
- the zero-based index of the flag to be setcond
- the condition- Returns:
- the collection of flags with the given flag possibly set
-