java.lang.Object
org.apache.jena.atlas.lib.BitsLong
Utilities for manipulating a bit pattern which are held in a 64 bit long.
Bits are numbered 0 to 63.
Bit 0 is the low bit of the long, and bit 63 the sign bit of the long.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic final longaccess(long bits, int start, int finish) Get the bits from start (inclusive) to finish (exclusive), leaving them aligned in the long.static final longclear(long bits, int bitIndex) Clear the bit specified.static final longclear(long bits, int start, int finish) Clear the bits specified.static final booleanisSet(long bits, int bitIndex) Test whether a bit is setstatic final longmask(int start, int finish) Create a mask that has ones between bit positions start (inc) and finish (exc), and zeros elsewhere.static final longmaskZero(int start, int finish) Create a mask that has zeros between bit positions start (inc) and finish (exc), and ones elsewherestatic final longpack(long bits, long value, int start, int finish) Place the value into the bit pattern between start and finish and returns the new value.static final longset(long bits, int bitIndex) Set the bits specified.static final longset(long bits, int start, int finish) Set the bits from start (inc) to finish (exc) to onestatic final booleantest(long bits, boolean isSet, int bitIndex) Test whether a bit is the same as isSetstatic final booleantest(long bits, long value, int start, int finish) Test whether a range has a specific value or notstatic final longunpack(long bits, int start, int finish) Extract the value packed into bits start (inclusive) and finish (exclusive), the value is returned shifted into the low part of the returned long.static final longGet bits from a hex string.
-
Method Details
-
unpack
public static final long unpack(long bits, int start, int finish) Extract the value packed into bits start (inclusive) and finish (exclusive), the value is returned shifted into the low part of the returned long. The low bit is bit zero.- Parameters:
bits-start-finish-- Returns:
- long
-
pack
public static final long pack(long bits, long value, int start, int finish) Place the value into the bit pattern between start and finish and returns the new value. Leaves other bits alone.- Parameters:
bits-value-start-finish-- Returns:
- long
-
unpack
Get bits from a hex string.- Parameters:
str-startChar- Index of first character (counted from the left, string style).finishChar- Index after the last character (counted from the left, string style).- Returns:
- long
- See Also:
-
set
public static final long set(long bits, int bitIndex) Set the bits specified.- Parameters:
bits- PatternbitIndex-- Returns:
- Modified pattern
-
set
public static final long set(long bits, int start, int finish) Set the bits from start (inc) to finish (exc) to one- Parameters:
bits- Patternstart- start (inclusive)finish- finish (exclusive)- Returns:
- Modified pattern
-
test
public static final boolean test(long bits, boolean isSet, int bitIndex) Test whether a bit is the same as isSet- Parameters:
bits- PatternisSet- Test whether is set or not.bitIndex- Bit index- Returns:
- Boolean
-
isSet
public static final boolean isSet(long bits, int bitIndex) Test whether a bit is set- Parameters:
bits- PatternbitIndex- Bit index- Returns:
- Boolean
-
test
public static final boolean test(long bits, long value, int start, int finish) Test whether a range has a specific value or not- Parameters:
bits- Patternvalue- Value to test forstart- start (inclusive)finish- finish (exclusive)- Returns:
- Boolean
-
access
public static final long access(long bits, int start, int finish) Get the bits from start (inclusive) to finish (exclusive), leaving them aligned in the long. See alsounpack(long, int, int)which returns the value found at that place.- Parameters:
bits-start-finish-- Returns:
- long
- See Also:
-
clear
public static final long clear(long bits, int bitIndex) Clear the bit specified.- Parameters:
bits-bitIndex-- Returns:
- long
-
clear
public static final long clear(long bits, int start, int finish) Clear the bits specified.- Parameters:
bits-start-finish-- Returns:
- long
-
mask
public static final long mask(int start, int finish) Create a mask that has ones between bit positions start (inc) and finish (exc), and zeros elsewhere.- Parameters:
start-finish-- Returns:
- long
-
maskZero
public static final long maskZero(int start, int finish) Create a mask that has zeros between bit positions start (inc) and finish (exc), and ones elsewhere- Parameters:
start-finish-- Returns:
- long
-