Package io.undertow.util
Class Bits
java.lang.Object
io.undertow.util.Bits
General bit-affecting utility methods.
- Author:
- David M. Lloyd
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanallAreClear(int var, int flags) Determine if all of theflagsin the givenvarare clear.static booleanallAreClear(long var, long flags) Determine if all of theflagsin the givenvarare clear.static booleanallAreSet(int var, int flags) Determine if all of theflagsin the givenvarare set.static booleanallAreSet(long var, long flags) Determine if all of theflagsin the givenvarare set.static booleananyAreClear(int var, int flags) Determine if any of theflagsin the givenvarare clear.static booleananyAreClear(long var, long flags) Determine if any of theflagsin the givenvarare clear.static booleananyAreSet(int var, int flags) Determine if any of theflagsin the givenvarare set.static booleananyAreSet(long var, long flags) Determine if any of theflagsin the givenvarare set.static charcharFromBytesBE(byte[] b, int off) Get a 16-bit signed big-endian char value from a byte array.static charcharFromBytesLE(byte[] b, int off) Get a 16-bit signed little-endian char value from a byte array.static intintBitMask(int low, int high) Get an integer bit mask consisting of 1 bits in the given range.static intintFromBytesBE(byte[] b, int off) Get a 32-bit signed big-endian int value from a byte array.static intintFromBytesLE(byte[] b, int off) Get a 32-bit signed little-endian int value from a byte array.static longlongBitMask(int low, int high) Get a long bit mask consisting of 1 bits in the given range.static longlongFromBytesBE(byte[] b, int off) Get a 64-bit signed big-endian long value from a byte array.static longlongFromBytesLE(byte[] b, int off) Get a 64-bit signed little-endian long value from a byte array.static intmediumFromBytesBE(byte[] b, int off) Get a 24-bit signed big-endian int value from a byte array.static intmediumFromBytesLE(byte[] b, int off) Get a 24-bit signed little-endian int value from a byte array.static shortshortFromBytesBE(byte[] b, int off) Get a 16-bit signed big-endian short value from a byte array.static shortshortFromBytesLE(byte[] b, int off) Get a 16-bit signed little-endian short value from a byte array.static intunsigned(byte v) Convert a signed value to unsigned.static longunsigned(int v) Convert a signed value to unsigned.static intunsigned(short v) Convert a signed value to unsigned.
-
Method Details
-
intBitMask
public static int intBitMask(int low, int high) Get an integer bit mask consisting of 1 bits in the given range. The returnedintwill have bitslowthroughhighset, 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 returnedlongwill have bitslowthroughhighset, 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 theflagsin the givenvarare set.- Parameters:
var- the value to testflags- the flags to test for- Returns:
trueif any offlagsare invar,falseotherwise
-
allAreSet
public static boolean allAreSet(int var, int flags) Determine if all of theflagsin the givenvarare set.- Parameters:
var- the value to testflags- the flags to test for- Returns:
trueif all offlagsare invar,falseotherwise
-
anyAreClear
public static boolean anyAreClear(int var, int flags) Determine if any of theflagsin the givenvarare clear.- Parameters:
var- the value to testflags- the flags to test for- Returns:
trueif not all offlagsare invar,falseotherwise
-
allAreClear
public static boolean allAreClear(int var, int flags) Determine if all of theflagsin the givenvarare clear.- Parameters:
var- the value to testflags- the flags to test for- Returns:
trueif none offlagsare invar,falseotherwise
-
anyAreSet
public static boolean anyAreSet(long var, long flags) Determine if any of theflagsin the givenvarare set.- Parameters:
var- the value to testflags- the flags to test for- Returns:
trueif any offlagsare invar,falseotherwise
-
allAreSet
public static boolean allAreSet(long var, long flags) Determine if all of theflagsin the givenvarare set.- Parameters:
var- the value to testflags- the flags to test for- Returns:
trueif all offlagsare invar,falseotherwise
-
anyAreClear
public static boolean anyAreClear(long var, long flags) Determine if any of theflagsin the givenvarare clear.- Parameters:
var- the value to testflags- the flags to test for- Returns:
trueif not all offlagsare invar,falseotherwise
-
allAreClear
public static boolean allAreClear(long var, long flags) Determine if all of theflagsin the givenvarare clear.- Parameters:
var- the value to testflags- the flags to test for- Returns:
trueif none offlagsare invar,falseotherwise
-
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
-