public final class BitUtils
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static boolean |
flagMatches(int word,
int flag)
Checks if a bitfield contains a certain flag.
|
static int |
toFlag(boolean value,
int flag)
Converts a boolean value to a specific bitflag.
|
public static boolean flagMatches(int word, int flag)
(word & flag) != 0
.
For example, flagMatches(0b1100, 0b0001)
returns false
, and
flagMatches(0b1100, 0b0100)
returns true
.
word
- the bitfield to checkflag
- the flag to checkpublic static int toFlag(boolean value, int flag)
For example, toFlag(isEnabled, ENABLED_FLAG)
returns ENABLED_FLAG
if isEnabled == true
,
and returns 0
if isEnabled == false
.
value
- the value to convertflag
- the bit representing the flagvalue
is true
, 0
if value
is false