Module 
Package org.xnio

Class Bits

java.lang.Object
org.xnio.Bits

public final class Bits extends Object
General bit-affecting utility methods.
Author:
David M. Lloyd
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    allAreClear(int var, int flags)
    Determine if all of the flags in the given var are clear.
    static boolean
    allAreClear(long var, long flags)
    Determine if all of the flags in the given var are clear.
    static boolean
    allAreSet(int var, int flags)
    Determine if all of the flags in the given var are set.
    static boolean
    allAreSet(long var, long flags)
    Determine if all of the flags in the given var are set.
    static boolean
    anyAreClear(int var, int flags)
    Determine if any of the flags in the given var are clear.
    static boolean
    anyAreClear(long var, long flags)
    Determine if any of the flags in the given var are clear.
    static boolean
    anyAreSet(int var, int flags)
    Determine if any of the flags in the given var are set.
    static boolean
    anyAreSet(long var, long flags)
    Determine if any of the flags in the given var 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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 returned int will have bits low through high set, and all other bits clear.
      Parameters:
      low - the low bit value
      high - 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 returned long will have bits low through high set, and all other bits clear.
      Parameters:
      low - the low bit value
      high - the high bit value
      Returns:
      the bit mask
    • anyAreSet

      public static boolean anyAreSet(int var, int flags)
      Determine if any of the flags in the given var are set.
      Parameters:
      var - the value to test
      flags - the flags to test for
      Returns:
      true if any of flags are in var, false otherwise
    • allAreSet

      public static boolean allAreSet(int var, int flags)
      Determine if all of the flags in the given var are set.
      Parameters:
      var - the value to test
      flags - the flags to test for
      Returns:
      true if all of flags are in var, false otherwise
    • anyAreClear

      public static boolean anyAreClear(int var, int flags)
      Determine if any of the flags in the given var are clear.
      Parameters:
      var - the value to test
      flags - the flags to test for
      Returns:
      true if not all of flags are in var, false otherwise
    • allAreClear

      public static boolean allAreClear(int var, int flags)
      Determine if all of the flags in the given var are clear.
      Parameters:
      var - the value to test
      flags - the flags to test for
      Returns:
      true if none of flags are in var, false otherwise
    • anyAreSet

      public static boolean anyAreSet(long var, long flags)
      Determine if any of the flags in the given var are set.
      Parameters:
      var - the value to test
      flags - the flags to test for
      Returns:
      true if any of flags are in var, false otherwise
    • allAreSet

      public static boolean allAreSet(long var, long flags)
      Determine if all of the flags in the given var are set.
      Parameters:
      var - the value to test
      flags - the flags to test for
      Returns:
      true if all of flags are in var, false otherwise
    • anyAreClear

      public static boolean anyAreClear(long var, long flags)
      Determine if any of the flags in the given var are clear.
      Parameters:
      var - the value to test
      flags - the flags to test for
      Returns:
      true if not all of flags are in var, false otherwise
    • allAreClear

      public static boolean allAreClear(long var, long flags)
      Determine if all of the flags in the given var are clear.
      Parameters:
      var - the value to test
      flags - the flags to test for
      Returns:
      true if none of flags are in var, 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 array
      off - 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 array
      off - 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 array
      off - 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 array
      off - 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 array
      off - 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 array
      off - 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 array
      off - 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 array
      off - 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 array
      off - 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 array
      off - the offset in the array
      Returns:
      the signed long value