- java.lang.Object
-
- org.xnio.Bits
-
public final class Bits extends java.lang.Object
General bit-affecting utility methods.- Author:
- David M. Lloyd
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
allAreClear(int var, int flags)
Determine if all of theflags
in the givenvar
are clear.static boolean
allAreClear(long var, long flags)
Determine if all of theflags
in the givenvar
are clear.static boolean
allAreSet(int var, int flags)
Determine if all of theflags
in the givenvar
are set.static boolean
allAreSet(long var, long flags)
Determine if all of theflags
in the givenvar
are set.static boolean
anyAreClear(int var, int flags)
Determine if any of theflags
in the givenvar
are clear.static boolean
anyAreClear(long var, long flags)
Determine if any of theflags
in the givenvar
are clear.static boolean
anyAreSet(int var, int flags)
Determine if any of theflags
in the givenvar
are set.static boolean
anyAreSet(long var, long flags)
Determine if any of theflags
in the givenvar
are set.static char
charFromBytesBE(byte[] b, int off)
Get a 16-bit signed big-endian char value from a byte array.static char
charFromBytesLE(byte[] b, int off)
Get a 16-bit signed little-endian char value from a byte array.static int
intBitMask(int low, int high)
Get an integer bit mask consisting of 1 bits in the given range.static int
intFromBytesBE(byte[] b, int off)
Get a 32-bit signed big-endian int value from a byte array.static int
intFromBytesLE(byte[] b, int off)
Get a 32-bit signed little-endian int value from a byte array.static long
longBitMask(int low, int high)
Get a long bit mask consisting of 1 bits in the given range.static long
longFromBytesBE(byte[] b, int off)
Get a 64-bit signed big-endian long value from a byte array.static long
longFromBytesLE(byte[] b, int off)
Get a 64-bit signed little-endian long value from a byte array.static int
mediumFromBytesBE(byte[] b, int off)
Get a 24-bit signed big-endian int value from a byte array.static int
mediumFromBytesLE(byte[] b, int off)
Get a 24-bit signed little-endian int value from a byte array.static short
shortFromBytesBE(byte[] b, int off)
Get a 16-bit signed big-endian short value from a byte array.static short
shortFromBytesLE(byte[] b, int off)
Get a 16-bit signed little-endian short value from a byte array.static int
unsigned(byte v)
Convert a signed value to unsigned.static long
unsigned(int v)
Convert a signed value to unsigned.static int
unsigned(short v)
Convert a signed value to unsigned.
-
-
-
Method Detail
-
intBitMask
public static int intBitMask(int low, int high)
Get an integer bit mask consisting of 1 bits in the given range. The returnedint
will have bitslow
throughhigh
set, and all other bits clear.- Parameters:
low
- the low bit valuehigh
- the high bit value- Returns:
- the bit mask
-
longBitMask
public static long longBitMask(int low, int high)
Get a long bit mask consisting of 1 bits in the given range. The returnedlong
will have bitslow
throughhigh
set, and all other bits clear.- Parameters:
low
- the low bit valuehigh
- the high bit value- Returns:
- the bit mask
-
anyAreSet
public static boolean anyAreSet(int var, int flags)
Determine if any of theflags
in the givenvar
are set.- Parameters:
var
- the value to testflags
- the flags to test for- Returns:
true
if any offlags
are invar
,false
otherwise
-
allAreSet
public static boolean allAreSet(int var, int flags)
Determine if all of theflags
in the givenvar
are set.- Parameters:
var
- the value to testflags
- the flags to test for- Returns:
true
if all offlags
are invar
,false
otherwise
-
anyAreClear
public static boolean anyAreClear(int var, int flags)
Determine if any of theflags
in the givenvar
are clear.- Parameters:
var
- the value to testflags
- the flags to test for- Returns:
true
if not all offlags
are invar
,false
otherwise
-
allAreClear
public static boolean allAreClear(int var, int flags)
Determine if all of theflags
in the givenvar
are clear.- Parameters:
var
- the value to testflags
- the flags to test for- Returns:
true
if none offlags
are invar
,false
otherwise
-
anyAreSet
public static boolean anyAreSet(long var, long flags)
Determine if any of theflags
in the givenvar
are set.- Parameters:
var
- the value to testflags
- the flags to test for- Returns:
true
if any offlags
are invar
,false
otherwise
-
allAreSet
public static boolean allAreSet(long var, long flags)
Determine if all of theflags
in the givenvar
are set.- Parameters:
var
- the value to testflags
- the flags to test for- Returns:
true
if all offlags
are invar
,false
otherwise
-
anyAreClear
public static boolean anyAreClear(long var, long flags)
Determine if any of theflags
in the givenvar
are clear.- Parameters:
var
- the value to testflags
- the flags to test for- Returns:
true
if not all offlags
are invar
,false
otherwise
-
allAreClear
public static boolean allAreClear(long var, long flags)
Determine if all of theflags
in the givenvar
are clear.- Parameters:
var
- the value to testflags
- the flags to test for- Returns:
true
if none offlags
are invar
,false
otherwise
-
unsigned
public static int unsigned(byte v)
Convert a signed value to unsigned.- Parameters:
v
- the signed byte- Returns:
- the unsigned byte, as an int
-
unsigned
public static int unsigned(short v)
Convert a signed value to unsigned.- Parameters:
v
- the signed short- Returns:
- the unsigned short, as an int
-
unsigned
public static long unsigned(int v)
Convert a signed value to unsigned.- Parameters:
v
- the signed int- Returns:
- the unsigned int, as a long
-
shortFromBytesLE
public static short shortFromBytesLE(byte[] b, int off)
Get a 16-bit signed little-endian short value from a byte array.- Parameters:
b
- the byte arrayoff
- the offset in the array- Returns:
- the signed short value
-
shortFromBytesBE
public static short shortFromBytesBE(byte[] b, int off)
Get a 16-bit signed big-endian short value from a byte array.- Parameters:
b
- the byte arrayoff
- the offset in the array- Returns:
- the signed short value
-
charFromBytesLE
public static char charFromBytesLE(byte[] b, int off)
Get a 16-bit signed little-endian char value from a byte array.- Parameters:
b
- the byte arrayoff
- the offset in the array- Returns:
- the signed char value
-
charFromBytesBE
public static char charFromBytesBE(byte[] b, int off)
Get a 16-bit signed big-endian char value from a byte array.- Parameters:
b
- the byte arrayoff
- the offset in the array- Returns:
- the signed char value
-
mediumFromBytesLE
public static int mediumFromBytesLE(byte[] b, int off)
Get a 24-bit signed little-endian int value from a byte array.- Parameters:
b
- the byte arrayoff
- the offset in the array- Returns:
- the signed medium value as an int
-
mediumFromBytesBE
public static int mediumFromBytesBE(byte[] b, int off)
Get a 24-bit signed big-endian int value from a byte array.- Parameters:
b
- the byte arrayoff
- the offset in the array- Returns:
- the signed medium value as an int
-
intFromBytesLE
public static int intFromBytesLE(byte[] b, int off)
Get a 32-bit signed little-endian int value from a byte array.- Parameters:
b
- the byte arrayoff
- the offset in the array- Returns:
- the signed int value
-
intFromBytesBE
public static int intFromBytesBE(byte[] b, int off)
Get a 32-bit signed big-endian int value from a byte array.- Parameters:
b
- the byte arrayoff
- the offset in the array- Returns:
- the signed int value
-
longFromBytesLE
public static long longFromBytesLE(byte[] b, int off)
Get a 64-bit signed little-endian long value from a byte array.- Parameters:
b
- the byte arrayoff
- the offset in the array- Returns:
- the signed long value
-
longFromBytesBE
public static long longFromBytesBE(byte[] b, int off)
Get a 64-bit signed big-endian long value from a byte array.- Parameters:
b
- the byte arrayoff
- the offset in the array- Returns:
- the signed long value
-
-