Class TypeConverter
java.lang.Object
org.sentrysoftware.ipmi.core.common.TypeConverter
Tool class for converting types.
-
Method Summary
Modifier and TypeMethodDescriptionstatic intbyteArrayToInt(byte[] value) Converts byte array in BigEndian convention to int.static intbyteToInt(byte value) Because Java doesn't support unsigned byte values, simple type casting leads to overflows and wrong values.static intdecode1sComplement(int value, int msb) Decodes 1's complement value that is encoded on lesser than 16 number of bits.static intdecode2sComplement(int value, int msb) Decodes 2's complement value that is encoded on lesser than 16 number of bits.static Stringdecode6bitAscii(byte[] text) static StringdecodeBcdPlus(byte[] text) Decodes text encoded in BCD plus format.static DatedecodeDate(int date) Decodes date encoded as number of seconds from 00:00:00, January 1, 1970 GMT.static byteintToByte(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[]intToLittleEndianByteArray(int value) Converts int to byte array in LittleEndian convention.static byte[]intToLittleEndianWord(int value) Converts int to LittleEndian word (double bytes array).static byte[]intToWord(int value) Converts int to BigEndian word (double bytes array).static booleanisBitSetOnPosition(int position, byte value) Checks whether single bit on given position is set in given little-endian byte.static intlittleEndianBcdByteToInt(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.static intlittleEndianByteArrayToInt(byte[] value) Converts byte array in LittleEndian convention to int.static intlittleEndianWordToInt(byte[] word) Converts LittleEndian word (double bytes array) to int.static bytesetBitOnPosition(int position, byte value) static intwordToInt(byte[] word) Converts BigEndian word (double bytes array) to int.
-
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 andMAX_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 andMAX_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 decodedmsb- - 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 decodedmsb- - 0-based index at which the encoded value begins- Returns:
- decoded value
-
decodeBcdPlus
Decodes text encoded in BCD plus format. -
decode6bitAscii
-
decodeDate
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)
-