com.twitter.common.collections
Class Bits

java.lang.Object
  extended by com.twitter.common.collections.Bits

public final class Bits
extends Object

Convenience class for doing bit-level operations on ints and longs.


Method Summary
static int clearBit(int value, int bit)
          Clears a bit in an int value.
static long clearBit(long value, int bit)
          Clears a bit in a long value.
static boolean isBitSet(int value, int bit)
          Tests whether a bit is set in an int value.
static boolean isBitSet(long value, int bit)
          Tests whether a bit is set in a long value.
static int setBit(int value, int bit)
          Sets a bit in an int value.
static long setBit(long value, int bit)
          Sets a bit in a long value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isBitSet

public static boolean isBitSet(int value,
                               int bit)
Tests whether a bit is set in an int value.

Parameters:
value - The bit field to test.
bit - The index of the bit to test, where bit 0 is the LSB.
Returns:
true if the bit is set, false otherwise.

isBitSet

public static boolean isBitSet(long value,
                               int bit)
Tests whether a bit is set in a long value.

Parameters:
value - The bit field to test.
bit - The index of the bit to test, where bit 0 is the LSB.
Returns:
true if the bit is set, false otherwise.

setBit

public static int setBit(int value,
                         int bit)
Sets a bit in an int value.

Parameters:
value - The bit field to modify.
bit - The index of the bit to set, where bit 0 is the LSB.
Returns:
The original value, with the indexed bit set.

setBit

public static long setBit(long value,
                          int bit)
Sets a bit in a long value.

Parameters:
value - The bit field to modify.
bit - The index of the bit to set, where bit 0 is the LSB.
Returns:
The original value, with the indexed bit set.

clearBit

public static int clearBit(int value,
                           int bit)
Clears a bit in an int value.

Parameters:
value - The bit field to modify.
bit - The index of the bit to clear, where bit 0 is the LSB.
Returns:
The original value, with the indexed bit clear.

clearBit

public static long clearBit(long value,
                            int bit)
Clears a bit in a long value.

Parameters:
value - The bit field to modify.
bit - The index of the bit to clear, where bit 0 is the LSB.
Returns:
The original value, with the indexed bit clear.