org.foray.common
Class Bit

java.lang.Object
  extended by org.foray.common.Bit

public final class Bit
extends Object

Utility class containing numeric routines, especially bit operators.


Method Summary
static boolean getBit(long input, int bit)
          Returns the value of a specific bit.
static byte maskHighOrderBits(byte input)
          Zeroes the 4 high-order bits in byte.
static byte maskLowOrderBits(byte input)
          Zeroes the 4 low-order bits in byte.
static int setBit(int input, int bit)
          Turns a specific bit value "on".
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

setBit

public static int setBit(int input,
                         int bit)
Turns a specific bit value "on".

Parameters:
input - The integer to be converted.
bit - The bit position to be set. Zero is the low-order bit.
Returns:
The converted integer. If bit is less than zero or more than 31, input is returned.

getBit

public static boolean getBit(long input,
                             int bit)
Returns the value of a specific bit.

Parameters:
input - The integer to be checked.
bit - The bit position to be checked. Zero is the low-order bit.
Returns:
True if the bit is on (1), or false if the bit is off (0).

maskHighOrderBits

public static byte maskHighOrderBits(byte input)
Zeroes the 4 high-order bits in byte.

Parameters:
input - The byte for which the high-order bits should be masked.
Returns:
The masked value.

maskLowOrderBits

public static byte maskLowOrderBits(byte input)
Zeroes the 4 low-order bits in byte.

Parameters:
input - The byte for which the low-order bits should be masked.
Returns:
The masked value.


Copyright © 2017. All rights reserved.