Class TypeConverter

java.lang.Object
org.sentrysoftware.ipmi.core.common.TypeConverter

public final class TypeConverter extends Object
Tool class for converting types.
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    byteArrayToInt(byte[] value)
    Converts byte array in BigEndian convention to int.
    static int
    byteToInt(byte value)
    Because Java doesn't support unsigned byte values, simple type casting leads to overflows and wrong values.
    static int
    decode1sComplement(int value, int msb)
    Decodes 1's complement value that is encoded on lesser than 16 number of bits.
    static int
    decode2sComplement(int value, int msb)
    Decodes 2's complement value that is encoded on lesser than 16 number of bits.
    static String
    decode6bitAscii(byte[] text)
     
    static String
    decodeBcdPlus(byte[] text)
    Decodes text encoded in BCD plus format.
    static Date
    decodeDate(int date)
    Decodes date encoded as number of seconds from 00:00:00, January 1, 1970 GMT.
    static byte
    intToByte(int value)
    Because Java doesn't support unsigned byte values, simple type casting leads to overflows and wrong values.
    static byte[]
    intToByteArray(int value)
    Converts int to byte array in BigEndian convention.
    static byte[]
    Converts int to byte array in LittleEndian convention.
    static byte[]
    Converts int to LittleEndian word (double bytes array).
    static byte[]
    intToWord(int value)
    Converts int to BigEndian word (double bytes array).
    static boolean
    isBitSetOnPosition(int position, byte value)
    Checks whether single bit on given position is set in given little-endian byte.
    static int
    Converts BCD encoded byte with bits 7:4 holding the Least Significant digit of the revision and bits 3:0 holding the Most Significant bits.
    static int
    Converts byte array in LittleEndian convention to int.
    static int
    littleEndianWordToInt(byte[] word)
    Converts LittleEndian word (double bytes array) to int.
    static byte
    setBitOnPosition(int position, byte value)
     
    static int
    wordToInt(byte[] word)
    Converts BigEndian word (double bytes array) to int.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • intToByteArray

      public static byte[] intToByteArray(int value)
      Converts int to byte array in BigEndian convention. Encodes unsigned byte in Java byte representation.
      Parameters:
      value -
      Returns:
      int converted to byte array
      See Also:
    • byteArrayToInt

      public static int byteArrayToInt(byte[] value)
      Converts byte array in BigEndian convention to int. Encodes unsigned byte in Java byte representation.
      Parameters:
      value - Byte array holding values.
      Returns:
      Byte array converted to int in a big endian convention.
      Throws:
      IndexOutOfBoundsException - when value's length is not 4.
      See Also:
    • intToLittleEndianByteArray

      public static byte[] intToLittleEndianByteArray(int value)
      Converts int to byte array in LittleEndian convention. Encodes unsigned byte in Java byte representation.
      Parameters:
      value -
      Returns:
      int converted to byte array
      See Also:
    • littleEndianByteArrayToInt

      public static int littleEndianByteArrayToInt(byte[] value)
      Converts byte array in LittleEndian convention to int. Encodes unsigned byte in Java byte representation.
      Parameters:
      value - Byte array holding values.
      Returns:
      Byte array converted to int in a little endian convention.
      Throws:
      IndexOutOfBoundsException - when value's length is not 4.
      See Also:
    • intToByte

      public static byte intToByte(int value)
      Because Java doesn't support unsigned byte values, simple type casting leads to overflows and wrong values. This function casts int to pseudo unsigned byte.
      Parameters:
      value - int value (must be in range 0-255)
      Returns:
      byte value
      Throws:
      IllegalArgumentException - when value is out of range.
    • byteToInt

      public static int byteToInt(byte value)
      Because Java doesn't support unsigned byte values, simple type casting leads to overflows and wrong values. This function casts pseudo unsigned byte to int.
      Parameters:
      value - byte value
      Returns:
      int value
    • intToWord

      public static byte[] intToWord(int value)
      Converts int to BigEndian word (double bytes array).
      Parameters:
      value - integer value to be converted to word (2-bytes array). Must be between 0 and MAX_WORD_SIZE.
      Returns:
      double bytes array
    • intToLittleEndianWord

      public static byte[] intToLittleEndianWord(int value)
      Converts int to LittleEndian word (double bytes array).
      Parameters:
      value - integer value to be converted to word (2-bytes array). Must be between 0 and MAX_WORD_SIZE.
      Returns:
      double bytes array
    • wordToInt

      public static int wordToInt(byte[] word)
      Converts BigEndian word (double bytes array) to int.
      Parameters:
      word - double bytes array.
      Returns:
      int value
    • littleEndianWordToInt

      public static int littleEndianWordToInt(byte[] word)
      Converts LittleEndian word (double bytes array) to int.
      Parameters:
      word - double bytes array.
      Returns:
      int value
    • littleEndianBcdByteToInt

      public static int littleEndianBcdByteToInt(byte value)
      Converts BCD encoded byte with bits 7:4 holding the Least Significant digit of the revision and bits 3:0 holding the Most Significant bits.
      Parameters:
      value - decoded value
      Returns:
      decoded value
    • decode2sComplement

      public static int decode2sComplement(int value, int msb)
      Decodes 2's complement value that is encoded on lesser than 16 number of bits.
      Parameters:
      value - - value to be decoded
      msb - - 0-based index at which the encoded value begins
      Returns:
      decoded value
    • decode1sComplement

      public static int decode1sComplement(int value, int msb)
      Decodes 1's complement value that is encoded on lesser than 16 number of bits.
      Parameters:
      value - - value to be decoded
      msb - - 0-based index at which the encoded value begins
      Returns:
      decoded value
    • decodeBcdPlus

      public static String decodeBcdPlus(byte[] text)
      Decodes text encoded in BCD plus format.
    • decode6bitAscii

      public static String decode6bitAscii(byte[] text)
    • decodeDate

      public static Date decodeDate(int date)
      Decodes date encoded as number of seconds from 00:00:00, January 1, 1970 GMT.
    • isBitSetOnPosition

      public static boolean isBitSetOnPosition(int position, byte value)
      Checks whether single bit on given position is set in given little-endian byte.
      Parameters:
      position - - position of bit to check. Allowed values are 0 - 7, where 0 is first (less significant) bit and 7 is last (most significant) bit.
      value - - byte in which we check the bytes.
      Returns:
    • setBitOnPosition

      public static byte setBitOnPosition(int position, byte value)