Top Description Constructors Methods
org.xnio

public final Class Bits

extends Object
Class Inheritance

General bit-affecting utility methods.
Author
David M. Lloyd

Constructor Summary

AccessConstructor and Description
private
Bits()

Method Summary

Modifier and TypeMethod and Description
public static boolean

Returns:

true if none of flags are in var, false otherwise
allAreClear
(int
the value to test
var
,
int
the flags to test for
flags
)

Determine if all of the flags in the given var are clear.

public static boolean

Returns:

true if none of flags are in var, false otherwise
allAreClear
(long
the value to test
var
,
long
the flags to test for
flags
)

Determine if all of the flags in the given var are clear.

public static boolean

Returns:

true if all of flags are in var, false otherwise
allAreSet
(int
the value to test
var
,
int
the flags to test for
flags
)

Determine if all of the flags in the given var are set.

public static boolean

Returns:

true if all of flags are in var, false otherwise
allAreSet
(long
the value to test
var
,
long
the flags to test for
flags
)

Determine if all of the flags in the given var are set.

public static boolean

Returns:

true if not all of flags are in var, false otherwise
anyAreClear
(int
the value to test
var
,
int
the flags to test for
flags
)

Determine if any of the flags in the given var are clear.

public static boolean

Returns:

true if not all of flags are in var, false otherwise
anyAreClear
(long
the value to test
var
,
long
the flags to test for
flags
)

Determine if any of the flags in the given var are clear.

public static boolean

Returns:

true if any of flags are in var, false otherwise
anyAreSet
(int
the value to test
var
,
int
the flags to test for
flags
)

Determine if any of the flags in the given var are set.

public static boolean

Returns:

true if any of flags are in var, false otherwise
anyAreSet
(long
the value to test
var
,
long
the flags to test for
flags
)

Determine if any of the flags in the given var are set.

public static char

Returns:

the signed char value
charFromBytesBE
(byte[]
the byte array
b
,
int
the offset in the array
off
)

Get a 16-bit signed big-endian char value from a byte array.

public static char

Returns:

the signed char value
charFromBytesLE
(byte[]
the byte array
b
,
int
the offset in the array
off
)

Get a 16-bit signed little-endian char value from a byte array.

public static int

Returns:

the bit mask
intBitMask
(int
the low bit value
low
,
int
the high bit value
high
)

Get an integer bit mask consisting of 1 bits in the given range.

public static int

Returns:

the signed int value
intFromBytesBE
(byte[]
the byte array
b
,
int
the offset in the array
off
)

Get a 32-bit signed big-endian int value from a byte array.

public static int

Returns:

the signed int value
intFromBytesLE
(byte[]
the byte array
b
,
int
the offset in the array
off
)

Get a 32-bit signed little-endian int value from a byte array.

public static long

Returns:

the bit mask
longBitMask
(int
the low bit value
low
,
int
the high bit value
high
)

Get a long bit mask consisting of 1 bits in the given range.

public static long

Returns:

the signed long value
longFromBytesBE
(byte[]
the byte array
b
,
int
the offset in the array
off
)

Get a 64-bit signed big-endian long value from a byte array.

public static long

Returns:

the signed long value
longFromBytesLE
(byte[]
the byte array
b
,
int
the offset in the array
off
)

Get a 64-bit signed little-endian long value from a byte array.

public static int

Returns:

the signed medium value as an int
mediumFromBytesBE
(byte[]
the byte array
b
,
int
the offset in the array
off
)

Get a 24-bit signed big-endian int value from a byte array.

public static int

Returns:

the signed medium value as an int
mediumFromBytesLE
(byte[]
the byte array
b
,
int
the offset in the array
off
)

Get a 24-bit signed little-endian int value from a byte array.

public static short

Returns:

the signed short value
shortFromBytesBE
(byte[]
the byte array
b
,
int
the offset in the array
off
)

Get a 16-bit signed big-endian short value from a byte array.

public static short

Returns:

the signed short value
shortFromBytesLE
(byte[]
the byte array
b
,
int
the offset in the array
off
)

Get a 16-bit signed little-endian short value from a byte array.

public static int

Returns:

the unsigned byte, as an int
unsigned
(byte
the signed byte
v
)

Convert a signed value to unsigned.

public static int

Returns:

the unsigned short, as an int
unsigned
(short
the signed short
v
)

Convert a signed value to unsigned.

public static long

Returns:

the unsigned int, as a long
unsigned
(int
the signed int
v
)

Convert a signed value to unsigned.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Bitsback to summary
private Bits()

Method Detail

allAreClearback to summary
public static boolean allAreClear(int var, int flags)

Determine if all of the flags in the given var are clear.

Parameters
var:int

the value to test

flags:int

the flags to test for

Returns:boolean

true if none of flags are in var, false otherwise

allAreClearback to summary
public static boolean allAreClear(long var, long flags)

Determine if all of the flags in the given var are clear.

Parameters
var:long

the value to test

flags:long

the flags to test for

Returns:boolean

true if none of flags are in var, false otherwise

allAreSetback to summary
public static boolean allAreSet(int var, int flags)

Determine if all of the flags in the given var are set.

Parameters
var:int

the value to test

flags:int

the flags to test for

Returns:boolean

true if all of flags are in var, false otherwise

allAreSetback to summary
public static boolean allAreSet(long var, long flags)

Determine if all of the flags in the given var are set.

Parameters
var:long

the value to test

flags:long

the flags to test for

Returns:boolean

true if all of flags are in var, false otherwise

anyAreClearback to summary
public static boolean anyAreClear(int var, int flags)

Determine if any of the flags in the given var are clear.

Parameters
var:int

the value to test

flags:int

the flags to test for

Returns:boolean

true if not all of flags are in var, false otherwise

anyAreClearback to summary
public static boolean anyAreClear(long var, long flags)

Determine if any of the flags in the given var are clear.

Parameters
var:long

the value to test

flags:long

the flags to test for

Returns:boolean

true if not all of flags are in var, false otherwise

anyAreSetback to summary
public static boolean anyAreSet(int var, int flags)

Determine if any of the flags in the given var are set.

Parameters
var:int

the value to test

flags:int

the flags to test for

Returns:boolean

true if any of flags are in var, false otherwise

anyAreSetback to summary
public static boolean anyAreSet(long var, long flags)

Determine if any of the flags in the given var are set.

Parameters
var:long

the value to test

flags:long

the flags to test for

Returns:boolean

true if any of flags are in var, false otherwise

charFromBytesBEback to summary
public static char charFromBytesBE(byte[] b, int off)

Get a 16-bit signed big-endian char value from a byte array.

Parameters
b:byte[]

the byte array

off:int

the offset in the array

Returns:char

the signed char value

charFromBytesLEback to summary
public static char charFromBytesLE(byte[] b, int off)

Get a 16-bit signed little-endian char value from a byte array.

Parameters
b:byte[]

the byte array

off:int

the offset in the array

Returns:char

the signed char value

intBitMaskback to summary
public static int intBitMask(int low, int high)

Get an integer bit mask consisting of 1 bits in the given range. The returned int will have bits low through high set, and all other bits clear.

Parameters
low:int

the low bit value

high:int

the high bit value

Returns:int

the bit mask

intFromBytesBEback to summary
public static int intFromBytesBE(byte[] b, int off)

Get a 32-bit signed big-endian int value from a byte array.

Parameters
b:byte[]

the byte array

off:int

the offset in the array

Returns:int

the signed int value

intFromBytesLEback to summary
public static int intFromBytesLE(byte[] b, int off)

Get a 32-bit signed little-endian int value from a byte array.

Parameters
b:byte[]

the byte array

off:int

the offset in the array

Returns:int

the signed int value

longBitMaskback to summary
public static long longBitMask(int low, int high)

Get a long bit mask consisting of 1 bits in the given range. The returned long will have bits low through high set, and all other bits clear.

Parameters
low:int

the low bit value

high:int

the high bit value

Returns:long

the bit mask

longFromBytesBEback to summary
public static long longFromBytesBE(byte[] b, int off)

Get a 64-bit signed big-endian long value from a byte array.

Parameters
b:byte[]

the byte array

off:int

the offset in the array

Returns:long

the signed long value

longFromBytesLEback to summary
public static long longFromBytesLE(byte[] b, int off)

Get a 64-bit signed little-endian long value from a byte array.

Parameters
b:byte[]

the byte array

off:int

the offset in the array

Returns:long

the signed long value

mediumFromBytesBEback to summary
public static int mediumFromBytesBE(byte[] b, int off)

Get a 24-bit signed big-endian int value from a byte array.

Parameters
b:byte[]

the byte array

off:int

the offset in the array

Returns:int

the signed medium value as an int

mediumFromBytesLEback to summary
public static int mediumFromBytesLE(byte[] b, int off)

Get a 24-bit signed little-endian int value from a byte array.

Parameters
b:byte[]

the byte array

off:int

the offset in the array

Returns:int

the signed medium value as an int

shortFromBytesBEback to summary
public static short shortFromBytesBE(byte[] b, int off)

Get a 16-bit signed big-endian short value from a byte array.

Parameters
b:byte[]

the byte array

off:int

the offset in the array

Returns:short

the signed short value

shortFromBytesLEback to summary
public static short shortFromBytesLE(byte[] b, int off)

Get a 16-bit signed little-endian short value from a byte array.

Parameters
b:byte[]

the byte array

off:int

the offset in the array

Returns:short

the signed short value

unsignedback to summary
public static int unsigned(byte v)

Convert a signed value to unsigned.

Parameters
v:byte

the signed byte

Returns:int

the unsigned byte, as an int

unsignedback to summary
public static int unsigned(short v)

Convert a signed value to unsigned.

Parameters
v:short

the signed short

Returns:int

the unsigned short, as an int

unsignedback to summary
public static long unsigned(int v)

Convert a signed value to unsigned.

Parameters
v:int

the signed int

Returns:long

the unsigned int, as a long