com.jpragma.snmp.util
Class BitManipulationHelper

java.lang.Object
  extended by com.jpragma.snmp.util.BitManipulationHelper

public final class BitManipulationHelper
extends java.lang.Object

Utility class for bit and byte array manipulation.

Author:
Isaac Levin

Method Summary
static boolean getBitValue(int value, int bitPosition)
          Returns bit value at specified position.
static byte[] intToByteArray(int number)
          Converts int to byte array.
static byte[] mergeArrays(byte[] buf1, byte[] buf2)
          Merges two byte arrays.
static byte[] removeLeadingZeroBytes(byte[] buf)
          Removes leading bytes with 0 value.
static int setBitValue(int value, int bitPosition, boolean bitValue)
          Sets bit at specified position.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getBitValue

public static boolean getBitValue(int value,
                                  int bitPosition)
Returns bit value at specified position.

Parameters:
value - original number
bitPosition - 1st bit is 1, last bit is 32
Returns:
true the the bit is turned on

setBitValue

public static int setBitValue(int value,
                              int bitPosition,
                              boolean bitValue)
Sets bit at specified position.

Parameters:
value - original number
bitPosition - bitPosition 1st bit is 1, last bit is 32
bitValue - true to turn the bit on
Returns:
new value

intToByteArray

public static byte[] intToByteArray(int number)
Converts int to byte array.

Parameters:
number - original number
Returns:
result array of bytes

removeLeadingZeroBytes

public static byte[] removeLeadingZeroBytes(byte[] buf)
Removes leading bytes with 0 value.

Parameters:
buf - original byte array
Returns:
Result byte array

mergeArrays

public static byte[] mergeArrays(byte[] buf1,
                                 byte[] buf2)
Merges two byte arrays.

Parameters:
buf1 - First byte array
buf2 - Second byte array
Returns:
Result byte array