Package org.esa.snap.core.util
Class BitSetter
- java.lang.Object
-
- org.esa.snap.core.util.BitSetter
-
public class BitSetter extends Object
Static function to manipulate bits inside an int or long.- Since:
- 4.1
-
-
Constructor Summary
Constructors Constructor Description BitSetter()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static 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
.
-
-
-
Method Detail
-
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
-
-