java.lang.Object
org.refcodes.numerical.NumericalUtility
This class contains some useful static methods for working with bitwise
operations objects.
CATION: This class may not have an optimized runtime behavior!
-
Method Summary
Modifier and TypeMethodDescriptionstatic int[]convertDigits(int aFromBase, int[] aDigits, int aToBase) Converts an array of digits of the provided "from" number base to an array of digits of the provided "to" number base.static StringconvertNumberBase(int aFromBase, char[] aFromCharSet, String aDigits, int aToBase, char[] aToCharSet) static StringconvertNumberBase(int aFromBase, String aDigits, int aToBase) static longfromDigits(int aFromBase, int[] aDigits) Converts an array of digits of the provided number base to a value.static longfromNumberBase(int aFromBase, char[] aFromCharSet, String aDigits) Converts a digitsStringof the provided number base to a value using the char set as digit representatives.static longfromNumberBase(int aFromBase, String aDigits) Converts a digitsStringof the provided number base to a value.static booleanisBitSetAt(long aValue, int aPosition) Determines the whether a bit at a given position of the provided is set.static bytesetBitAt(byte aValue, int aPos, boolean aBit) Sets the bit of the given value at the given bit position as specified.static intsum(int... aSummands) Calculates the sum from the provided summands.static byte[]toBigEndianBytes(double aValue) Converts the given value to a byte array in big endian notation.static byte[]toBigEndianBytes(float aValue) Converts the given value to a byte array in big endian notation.static byte[]toBigEndianBytes(int aValue) Converts the given value to a byte array in big endian notation.static byte[]toBigEndianBytes(long aValue) Converts the given value to a byte array in big endian notation.static byte[]toBigEndianBytes(long aValue, int aLength) Converts the given value to a byte array in big endian notation.static byte[]toBigEndianBytes(short aValue) Converts the given value to a byte array in big endian notation.static booleanConverts the given String to a boolean value.static boolean[]toBooleans(byte[] aBytes) Converts the bits contained within the given byte array to a boolean array.static boolean[]toBooleans(byte[] aBytes, int aLength) Converts the bits contained within the given byte array to a boolean array.static boolean[]toBooleans(byte[] aBytes, int aOffset, int aLength) Converts the bits contained within the given byte array to a boolean array.static byte[]toBytes(boolean[] aBits) Converts a boolean array to a byte array using the byte's bits to represent the according boolean values.static byte[]toBytes(int aInteger) Converts a integer value to an array of bytes, left byte being the most significant one (highest order).static byte[]toBytes(long aLong) Converts a long value to an array of bytes, left byte being the most significant one (highest order).static byte[]Converts a double value to an array of bytes, left(?)static byte[]Converts aStringcontaining "verbose" bytes into an array of bytes.static byte[]Converts aStringcontaining "verbose" bytes into an array of bytes.static int[]toDigits(long aValue, int aToBase) Converts a value to an array of digits of the provided number base.static doubletoDouble(int aIntValue, double aMinDouble, double aMaxDouble) Converts the given integer value to a double of the given range.static doubletoDouble(long aLongValue, double aMinDouble, double aMaxDouble) Converts the given long value to a double of the given range.static doubleCreates a double between 0 and 1 from aString; useful e.g. when creating a number from a pass-phrase.static doubletoDoubleFromBigEndianBytes(byte[] aBigEndian) Converts a byte array in big endian to a double value.static doubletoDoubleFromLittleEndianBytes(byte[] aLittleEndian) Converts a byte array in big little to a double value.static double[]Creates an array with double values between 0 and 1 from aStringuseful e.g. when creating a bunch of numbers from a pass-phrase.static floattoFloatFromBigEndianBytes(byte[] aBigEndian) Converts a byte array in big endian to a float value.static floattoFloatFromLittleEndianBytes(byte[] aLittleEndian) Converts a byte array in big little to a float value.static inttoHashCode(Object... aObjects) Calculates a hash code from the given object's hash codes.static inttoHashCode(String aValue) Calculates a Java-Version's implementation independent Hash-Code.static int[]toHashCodes(char[] aSource, int aCount) Creates a given number of IDs from the provided source text.static int[]toHashCodes(String aSource, int aCount) Creates a given number of IDs from the provided source text.static StringtoHexString(boolean isPrefixBytes, byte... aBytes) Converts the provided bytes to a hexadecimalStringrepresentation.static StringtoHexString(byte aByte) Converts the provided byte to a hexadecimalStringrepresentation.static StringtoHexString(byte... aBytes) Converts the provided bytes to a hexadecimalStringrepresentation.static StringtoHexString(byte[] aBytes, int aBytesPerLine) Converts the provided bytes to a hexadecimalStringrepresentation.static StringtoHexString(byte[] aBytes, int aBytesPerLine, boolean isPrefixBytes) Converts the provided bytes to a hexadecimalStringrepresentation.static StringtoHexString(byte[] aBytes, String aByteSeparator) Converts the provided bytes to a hexadecimalStringrepresentation.static StringtoHexString(byte[] aBytes, String aByteSeparator, boolean isPrefixBytes) Converts the provided bytes to a hexadecimalStringrepresentation.static StringtoHexString(byte[] aBytes, String aByteSeparator, int aBytesPerLine) Converts the provided bytes to a hexadecimalStringrepresentation.static StringtoHexString(byte[] aBytes, String aByteSeparator, int aBytesPerLine, boolean isPrefixBytes) Converts the provided bytes to a hexadecimalStringrepresentation.static StringtoHexString(byte aByte, boolean isPrefixByte) Converts the provided byte to a hexadecimalStringrepresentation.static StringtoHexString(int aByte) Converts the provided byte (in integer notation as ofInputStreamandOutputStreaminteger based byte operations)to a hexadecimalStringrepresentation.static StringtoHexString(int aByte, boolean isPrefixByte) Converts the provided byte (in integer notation as ofInputStreamandOutputStreaminteger based byte operations) to a hexadecimalStringrepresentation.static StringtoHexString(int aBytesPerLine, boolean isPrefixBytes, byte... aBytes) Converts the provided bytes to a hexadecimalStringrepresentation.static StringtoHexString(int aBytesPerLine, byte... aBytes) Converts the provided bytes to a hexadecimalStringrepresentation.static StringtoHexString(String aByteSeparator, boolean isPrefixBytes, byte... aBytes) Converts the provided bytes to a hexadecimalStringrepresentation.static StringtoHexString(String aByteSeparator, byte... aBytes) Converts the provided bytes to a hexadecimalStringrepresentation.static StringtoHexString(String aByteSeparator, int aBytesPerLine, boolean isPrefixBytes, byte... aBytes) Converts the provided bytes to a hexadecimalStringrepresentation.static StringtoHexString(String aByteSeparator, int aBytesPerLine, byte... aBytes) Converts the provided bytes to a hexadecimalStringrepresentation.static inttoInt(byte[] aBytes) Converts an integer value from the given byte array.static inttoInt(byte[] aBytes, int aOffset) Converts an integer value from the given byte array.static inttoIntFromBigEndianBytes(byte[] aBigEndian) Converts a byte array in big endian to an integer value.static inttoIntFromLittleEndianBytes(byte[] aLittleEndian) Converts a byte array in little endian to an integer value.static byte[]toLittleEndianBytes(double aValue) Converts the given value to a byte array in big endian notation.static byte[]toLittleEndianBytes(float aValue) Converts the given value to a byte array in big endian notation.static byte[]toLittleEndianBytes(int aValue) Converts the given value to a byte array in little endian notation.static byte[]toLittleEndianBytes(long aValue) Converts the given value to a byte array in little endian notation.static byte[]toLittleEndianBytes(long aValue, int aLength) Converts the given value to a byte array in little endian notation.static byte[]toLittleEndianBytes(short aValue) Converts the given value to a byte array in little endian notation.static longtoLong(byte[] aBytes) Converts a long value from the given byte array.static longtoLong(byte[] aBytes, int aOffset) Converts a long value from the given byte array.static longCreates a long from aString; useful e.g. when creating a number from a pass-phrase.static longtoLongFromBigEndianBytes(byte[] aBigEndian) Converts a byte array in big endian to a long value.static longtoLongFromLittleEndianBytes(byte[] aLittleEndian) Converts a byte array in little endian to a long value.static StringGenerates a md5 hash of the given text.static StringtoNumberBase(long aValue, int aToBase) Converts a value to aStringof digits of the provided number base.static StringtoNumberBase(long aValue, int aToBase, char[] aToCharSet) Converts a value to aStringof digits of the provided number base using the char set as digit representatives.static doubletoScaled(double aValue, double aMin, double aMax) Scales the given value (which must be between 0 .. 1 to be between aMin .. aMax.static shorttoShortFromBigEndianBytes(byte[] aBigEndian) Converts a byte array in big endian to an short value.static shorttoShortFromLittleEndianBytes(byte[] aLittleEndian) Converts a byte array in little endian to an short value.static short[]toShorts(byte[] aBytes) Converts a byte array to a short array.static byte[]toUnsignedBigEndianBytes(byte[] aBigEndian) Converts the given byte array to a byte array representing an unsigned value.static byte[]toUnsignedBigEndianBytes(int aValue) Converts the given "unsigned" (it is to be treated as if it were unsigned) value to a byte array in big endian notation.static byte[]toUnsignedBigEndianBytes(long aValue) Converts the given "unsigned" (it is to be treated as if it were unsigned) value to a byte array in big endian notation.static byte[]toUnsignedBigEndianBytes(long aValue, int aLength) Converts the given "unsigned" (it is to be treated as if it were unsigned) value to a byte array in big endian notation.static byte[]toUnsignedBigEndianBytes(short aValue) Converts the given "unsigned" (it is to be treated as if it were unsigned) value to a byte array in big endian notation.static inttoUnsignedIntFromBigEndianBytes(byte[] aBigEndian) Converts the given "unsigned" (it is to be treated as if it were unsigned) byte array in big endian to a long value.static inttoUnsignedIntFromLittleEndianBytes(byte[] aLittleEndian) Converts the given "unsigned" (it is to be treated as if it were unsigned) byte array in big endian to a long value.static byte[]toUnsignedLittleEndianBytes(byte[] aLittleEndian) Converts the given byte array to a byte array representing an unsigned value.static byte[]toUnsignedLittleEndianBytes(int aValue) Converts the given "unsigned" (it is to be treated as if it were unsigned) value to a byte array in little endian notation.static byte[]toUnsignedLittleEndianBytes(long aValue) Converts the given "unsigned" (it is to be treated as if it were unsigned) value to a byte array in little endian notation.static byte[]toUnsignedLittleEndianBytes(long aValue, int aLength) Converts the given "unsigned" (it is to be treated as if it were unsigned) value to a byte array in little endian notation.static byte[]toUnsignedLittleEndianBytes(short aValue) Converts the given "unsigned" (it is to be treated as if it were unsigned) value to a byte array in little endian notation.static longtoUnsignedLong(int aSignedIntValue) Converts a signed int to an unsigned long value.static longtoUnsignedLongFromBigEndianBytes(byte[] aBigEndian) Converts the given "unsigned" (it is to be treated as if it were unsigned)a byte array in big endian to a long value.static longtoUnsignedLongFromLittleEndianBytes(byte[] aLittleEndian) Converts the given "unsigned" (it is to be treated as if it were unsigned) byte array in little endian to a long value.static shorttoUnsignedShortFromBigEndianBytes(byte[] aBigEndian) Converts the given "unsigned" (it is to be treated as if it were unsigned) byte array in big endian to a long value.static shorttoUnsignedShortFromLittleEndianBytes(byte[] aLittleEndian) Converts the given "unsigned" (it is to be treated as if it were unsigned) byte array in big endian to a long value.
-
Method Details
-
toNumberBase
Converts a value to aStringof digits of the provided number base.- Parameters:
aValue- The value to be converted.aToBase- The number base to which to convert.- Returns:
- The according digits'
String.
-
fromNumberBase
Converts a digitsStringof the provided number base to a value.- Parameters:
aFromBase- The number base from which to convert.aDigits- The digits'Stringto be converted back to a value.- Returns:
- The according value.
-
convertNumberBase
-
toNumberBase
Converts a value to aStringof digits of the provided number base using the char set as digit representatives.- Parameters:
aValue- The value to be converted.aToBase- The number base to which to convert.aToCharSet- The char set representing the digits.- Returns:
- The according digits'
String.
-
fromNumberBase
Converts a digitsStringof the provided number base to a value using the char set as digit representatives.- Parameters:
aFromBase- The number base from which to convert.aFromCharSet- The char set representing the digits.aDigits- The digits'Stringto be converted back to a value.- Returns:
- The according value.
-
convertNumberBase
public static String convertNumberBase(int aFromBase, char[] aFromCharSet, String aDigits, int aToBase, char[] aToCharSet) Converts a digits'Stringof the provided "from" number base to a digits'Stringof the provided "to" number base using the "from" and "to" char sets as digit representatives.- Parameters:
aFromBase- The number base from which to convert.aFromCharSet- The char set representing the digits.aDigits- The digits'Stringto be converted.aToBase- The number base to which to convert.aToCharSet- The char set representing the digits.- Returns:
- The accordingly converted digits'
String.
-
toDigits
public static int[] toDigits(long aValue, int aToBase) Converts a value to an array of digits of the provided number base.- Parameters:
aValue- The value to be converted.aToBase- The number base to which to convert.- Returns:
- The according digits.
-
fromDigits
public static long fromDigits(int aFromBase, int[] aDigits) Converts an array of digits of the provided number base to a value.- Parameters:
aFromBase- The number base from which to convert.aDigits- The digits to be converted back to a value.- Returns:
- The according value.
-
convertDigits
public static int[] convertDigits(int aFromBase, int[] aDigits, int aToBase) Converts an array of digits of the provided "from" number base to an array of digits of the provided "to" number base.- Parameters:
aFromBase- The number base from which to convert.aDigits- The digits to be converted.aToBase- The number base to which to convert.- Returns:
- The accordingly converted digits.
-
isBitSetAt
public static boolean isBitSetAt(long aValue, int aPosition) Determines the whether a bit at a given position of the provided is set.- Parameters:
aValue- The value which's bits to test.aPosition- The position of the bit in question.- Returns:
- True in case it is set, else false,
-
setBitAt
public static byte setBitAt(byte aValue, int aPos, boolean aBit) Sets the bit of the given value at the given bit position as specified.- Parameters:
aValue- The value where to set the bit.aPos- The bit of the value which to set accordingly.aBit- The value of the bit.- Returns:
- The byte with the according bit set accordingly.
-
toBytes
Converts aStringcontaining "verbose" bytes into an array of bytes. TheStringmight look as follows: "100,12,0x14, 0xFF". Hexadecimal values must(!) be prefixed with "X0" or "x0"!- Parameters:
aString- The String which is to be converted into bytes.- Returns:
- The according byte array.
- Throws:
IllegalArgumentException- in case the providedStringcontains illegal characters.NumberFormatException- in case the String contains values which cannot be parsed.
-
toBytes
Converts aStringcontaining "verbose" bytes into an array of bytes. TheStringmight look as follows: "100,12,0x14, 0xFF"- Parameters:
aString- The String which is to be converted into bytes.isHexString- True in case you provide a hexadecimalStringwhich may not have "0X" prefixed to its values. E.g. each value is treated as being hexadecimal.- Returns:
- The according byte array.
- Throws:
IllegalArgumentException- in case the providedStringcontains illegal characters.NumberFormatException- in case the String contains values which cannot be parsed.
-
toBytes
public static byte[] toBytes(long aLong) Converts a long value to an array of bytes, left byte being the most significant one (highest order).- Parameters:
aLong- The long value to be converted- Returns:
- The array of bytes representing the long value.
-
toBytes
public static byte[] toBytes(int aInteger) Converts a integer value to an array of bytes, left byte being the most significant one (highest order).- Parameters:
aInteger- The integer value to be converted- Returns:
- The array of bytes representing the long value.
-
toBytes
public static byte[] toBytes(boolean[] aBits) Converts a boolean array to a byte array using the byte's bits to represent the according boolean values. Attention: Trailing bits of the last byte might need to be ignored in case the length of the boolean array is not a multiple of 8.- Parameters:
aBits- The boolean array to convert.- Returns:
- The byte array which's bits represent the according boolean array's values.
-
toBooleans
public static boolean[] toBooleans(byte[] aBytes) Converts the bits contained within the given byte array to a boolean array.- Parameters:
aBytes- The bytes to be converted.- Returns:
- The according boolean array.
-
toBooleans
public static boolean[] toBooleans(byte[] aBytes, int aLength) Converts the bits contained within the given byte array to a boolean array.- Parameters:
aBytes- The bytes to be converted.aLength- The length of the resulting boolean array.- Returns:
- The according boolean array.
-
toBooleans
public static boolean[] toBooleans(byte[] aBytes, int aOffset, int aLength) Converts the bits contained within the given byte array to a boolean array.- Parameters:
aBytes- The bytes to be converted.aOffset- The offset of the bytes from where to start converting.aLength- The length of the resulting boolean array.- Returns:
- The according boolean array.
-
toLong
public static long toLong(byte[] aBytes) Converts a long value from the given byte array.- Parameters:
aBytes- The bytes to convert.- Returns:
- The resulting long value.
-
toLong
public static long toLong(byte[] aBytes, int aOffset) Converts a long value from the given byte array.- Parameters:
aBytes- The bytes to convert.aOffset- The offset from where to start conversion.- Returns:
- The resulting long value.
- Throws:
IllegalArgumentException- the illegal argument exception
-
toInt
public static int toInt(byte[] aBytes) Converts an integer value from the given byte array.- Parameters:
aBytes- The bytes to convert.- Returns:
- The resulting integer value.
-
toInt
public static int toInt(byte[] aBytes, int aOffset) Converts an integer value from the given byte array.- Parameters:
aBytes- The bytes to convert.aOffset- The offset from where to start conversion.- Returns:
- The resulting integer value.
-
toShorts
public static short[] toShorts(byte[] aBytes) Converts a byte array to a short array.- Parameters:
aBytes- The bytes to be converted to short.- Returns:
- The according short array.
-
toBytes
Converts a double value to an array of bytes, left(?) byte being the most significant one (highest order).- Parameters:
aDouble- The double value to be converted- Returns:
- The array of bytes representing the double value.
-
toLong
Creates a long from aString; useful e.g. when creating a number from a pass-phrase. -
toDouble
Creates a double between 0 and 1 from aString; useful e.g. when creating a number from a pass-phrase. -
toDoubles
Creates an array with double values between 0 and 1 from aStringuseful e.g. when creating a bunch of numbers from a pass-phrase. -
toHashCode
Calculates a hash code from the given object's hash codes.- Parameters:
aObjects- The objects for which to calculate the has codes.- Returns:
- The hash codes for the given objects.
-
toUnsignedLong
public static long toUnsignedLong(int aSignedIntValue) Converts a signed int to an unsigned long value. This is not do a simple ABS function, here we take a look at the bits of the value and calculate which the unsigned (positive) value would be. The positive value is returned in a (signed) long value.- Parameters:
aSignedIntValue- The signed integer value.- Returns:
- The unsigned long value.
-
toLittleEndianBytes
public static byte[] toLittleEndianBytes(long aValue, int aLength) Converts the given value to a byte array in little endian notation.- Parameters:
aValue- The value for which to get the byte array.aLength- The number of bytes to use.- Returns:
- The according array.
-
toLittleEndianBytes
public static byte[] toLittleEndianBytes(long aValue) Converts the given value to a byte array in little endian notation.- Parameters:
aValue- The value for which to get the byte array.- Returns:
- The according array.
-
toLittleEndianBytes
public static byte[] toLittleEndianBytes(int aValue) Converts the given value to a byte array in little endian notation.- Parameters:
aValue- The value for which to get the byte array.- Returns:
- The according array.
-
toLittleEndianBytes
public static byte[] toLittleEndianBytes(short aValue) Converts the given value to a byte array in little endian notation.- Parameters:
aValue- The value for which to get the byte array.- Returns:
- The according array.
-
toBigEndianBytes
public static byte[] toBigEndianBytes(long aValue, int aLength) Converts the given value to a byte array in big endian notation.- Parameters:
aValue- The value for which to get the byte array.aLength- The number of bytes to use.- Returns:
- The according array,
-
toBigEndianBytes
public static byte[] toBigEndianBytes(long aValue) Converts the given value to a byte array in big endian notation.- Parameters:
aValue- The value for which to get the byte array.- Returns:
- The according array.
-
toBigEndianBytes
public static byte[] toBigEndianBytes(int aValue) Converts the given value to a byte array in big endian notation.- Parameters:
aValue- The value for which to get the byte array.- Returns:
- The according array.
-
toBigEndianBytes
public static byte[] toBigEndianBytes(short aValue) Converts the given value to a byte array in big endian notation.- Parameters:
aValue- The value for which to get the byte array.- Returns:
- The according array.
-
toUnsignedLittleEndianBytes
public static byte[] toUnsignedLittleEndianBytes(long aValue, int aLength) Converts the given "unsigned" (it is to be treated as if it were unsigned) value to a byte array in little endian notation.- Parameters:
aValue- The value for which to get the byte array.aLength- The number of bytes to use.- Returns:
- The according array.
-
toUnsignedLittleEndianBytes
public static byte[] toUnsignedLittleEndianBytes(long aValue) Converts the given "unsigned" (it is to be treated as if it were unsigned) value to a byte array in little endian notation.- Parameters:
aValue- The value for which to get the byte array.- Returns:
- The according array.
-
toUnsignedLittleEndianBytes
public static byte[] toUnsignedLittleEndianBytes(int aValue) Converts the given "unsigned" (it is to be treated as if it were unsigned) value to a byte array in little endian notation.- Parameters:
aValue- The value for which to get the byte array.- Returns:
- The according array.
-
toUnsignedLittleEndianBytes
public static byte[] toUnsignedLittleEndianBytes(short aValue) Converts the given "unsigned" (it is to be treated as if it were unsigned) value to a byte array in little endian notation.- Parameters:
aValue- The value for which to get the byte array.- Returns:
- The according array.
-
toUnsignedBigEndianBytes
public static byte[] toUnsignedBigEndianBytes(long aValue, int aLength) Converts the given "unsigned" (it is to be treated as if it were unsigned) value to a byte array in big endian notation.- Parameters:
aValue- The value for which to get the byte array.aLength- The number of bytes to use.- Returns:
- The according array.
-
toUnsignedBigEndianBytes
public static byte[] toUnsignedBigEndianBytes(long aValue) Converts the given "unsigned" (it is to be treated as if it were unsigned) value to a byte array in big endian notation.- Parameters:
aValue- The value for which to get the byte array.- Returns:
- The according array.
-
toUnsignedBigEndianBytes
public static byte[] toUnsignedBigEndianBytes(int aValue) Converts the given "unsigned" (it is to be treated as if it were unsigned) value to a byte array in big endian notation.- Parameters:
aValue- The value for which to get the byte array.- Returns:
- The according array.
-
toUnsignedBigEndianBytes
public static byte[] toUnsignedBigEndianBytes(short aValue) Converts the given "unsigned" (it is to be treated as if it were unsigned) value to a byte array in big endian notation.- Parameters:
aValue- The value for which to get the byte array.- Returns:
- The according array.
-
toLongFromLittleEndianBytes
public static long toLongFromLittleEndianBytes(byte[] aLittleEndian) Converts a byte array in little endian to a long value.- Parameters:
aLittleEndian- The byte array to be converted.- Returns:
- The resulting long value.
-
toUnsignedLongFromLittleEndianBytes
public static long toUnsignedLongFromLittleEndianBytes(byte[] aLittleEndian) Converts the given "unsigned" (it is to be treated as if it were unsigned) byte array in little endian to a long value.- Parameters:
aLittleEndian- The byte array to be converted.- Returns:
- The resulting long value.
-
toLongFromBigEndianBytes
public static long toLongFromBigEndianBytes(byte[] aBigEndian) Converts a byte array in big endian to a long value.- Parameters:
aBigEndian- The byte array to be converted.- Returns:
- The resulting long value.
-
toUnsignedLongFromBigEndianBytes
public static long toUnsignedLongFromBigEndianBytes(byte[] aBigEndian) Converts the given "unsigned" (it is to be treated as if it were unsigned)a byte array in big endian to a long value.- Parameters:
aBigEndian- The byte array to be converted.- Returns:
- The resulting long value.
-
toIntFromLittleEndianBytes
public static int toIntFromLittleEndianBytes(byte[] aLittleEndian) Converts a byte array in little endian to an integer value.- Parameters:
aLittleEndian- The byte array to be converted.- Returns:
- The resulting integer value.
-
toUnsignedIntFromLittleEndianBytes
public static int toUnsignedIntFromLittleEndianBytes(byte[] aLittleEndian) Converts the given "unsigned" (it is to be treated as if it were unsigned) byte array in big endian to a long value.- Parameters:
aLittleEndian- The byte array to be converted.- Returns:
- The resulting long value.
-
toIntFromBigEndianBytes
public static int toIntFromBigEndianBytes(byte[] aBigEndian) Converts a byte array in big endian to an integer value.- Parameters:
aBigEndian- The byte array to be converted.- Returns:
- The resulting integer value.
-
toUnsignedIntFromBigEndianBytes
public static int toUnsignedIntFromBigEndianBytes(byte[] aBigEndian) Converts the given "unsigned" (it is to be treated as if it were unsigned) byte array in big endian to a long value.- Parameters:
aBigEndian- The byte array to be converted.- Returns:
- The resulting long value.
-
toShortFromLittleEndianBytes
public static short toShortFromLittleEndianBytes(byte[] aLittleEndian) Converts a byte array in little endian to an short value.- Parameters:
aLittleEndian- The byte array to be converted.- Returns:
- The resulting short value.
-
toUnsignedShortFromLittleEndianBytes
public static short toUnsignedShortFromLittleEndianBytes(byte[] aLittleEndian) Converts the given "unsigned" (it is to be treated as if it were unsigned) byte array in big endian to a long value.- Parameters:
aLittleEndian- The byte array to be converted.- Returns:
- The resulting long value.
-
toShortFromBigEndianBytes
public static short toShortFromBigEndianBytes(byte[] aBigEndian) Converts a byte array in big endian to an short value.- Parameters:
aBigEndian- The byte array to be converted.- Returns:
- The resulting short value.
-
toUnsignedShortFromBigEndianBytes
public static short toUnsignedShortFromBigEndianBytes(byte[] aBigEndian) Converts the given "unsigned" (it is to be treated as if it were unsigned) byte array in big endian to a long value.- Parameters:
aBigEndian- The byte array to be converted.- Returns:
- The resulting long value.
-
toUnsignedLittleEndianBytes
public static byte[] toUnsignedLittleEndianBytes(byte[] aLittleEndian) Converts the given byte array to a byte array representing an unsigned value.- Parameters:
aLittleEndian- The byte array to be converted to be unsigned.- Returns:
- The unsigned byte array, usually one byte longer.
-
toUnsignedBigEndianBytes
public static byte[] toUnsignedBigEndianBytes(byte[] aBigEndian) Converts the given byte array to a byte array representing an unsigned value.- Parameters:
aBigEndian- The byte array to be converted to be unsigned.- Returns:
- The unsigned byte array, usually one byte longer.
-
toFloatFromBigEndianBytes
public static float toFloatFromBigEndianBytes(byte[] aBigEndian) Converts a byte array in big endian to a float value.- Parameters:
aBigEndian- The byte array to be converted.- Returns:
- The resulting float value.
-
toFloatFromLittleEndianBytes
public static float toFloatFromLittleEndianBytes(byte[] aLittleEndian) Converts a byte array in big little to a float value.- Parameters:
aLittleEndian- The byte array to be converted.- Returns:
- The resulting float value.
-
toBigEndianBytes
public static byte[] toBigEndianBytes(float aValue) Converts the given value to a byte array in big endian notation. The length for a long are 32 bits, so the result will be 4 bytes long.- Parameters:
aValue- The value for which to get the byte array.- Returns:
- The according array.
-
toLittleEndianBytes
public static byte[] toLittleEndianBytes(float aValue) Converts the given value to a byte array in big endian notation. The length for a long are 32 bits, so the result will be 4 bytes long.- Parameters:
aValue- The value for which to get the byte array.- Returns:
- The according array.
-
toDoubleFromBigEndianBytes
public static double toDoubleFromBigEndianBytes(byte[] aBigEndian) Converts a byte array in big endian to a double value.- Parameters:
aBigEndian- The byte array to be converted.- Returns:
- The resulting double value.
-
toDoubleFromLittleEndianBytes
public static double toDoubleFromLittleEndianBytes(byte[] aLittleEndian) Converts a byte array in big little to a double value.- Parameters:
aLittleEndian- The byte array to be converted.- Returns:
- The resulting double value.
-
toBigEndianBytes
public static byte[] toBigEndianBytes(double aValue) Converts the given value to a byte array in big endian notation. The length for a long are 64 bits, so the result will be 4 bytes long.- Parameters:
aValue- The value for which to get the byte array.- Returns:
- The according array.
-
toLittleEndianBytes
public static byte[] toLittleEndianBytes(double aValue) Converts the given value to a byte array in big endian notation. The length for a long are 64 bits, so the result will be 4 bytes long.- Parameters:
aValue- The value for which to get the byte array.- Returns:
- The according array.
-
toHexString
Converts the provided bytes to a hexadecimalStringrepresentation. -
toHexString
Converts the provided bytes to a hexadecimalStringrepresentation. -
toHexString
Converts the provided bytes to a hexadecimalStringrepresentation. -
toHexString
Converts the provided bytes to a hexadecimalStringrepresentation. -
toHexString
Converts the provided bytes to a hexadecimalStringrepresentation. -
toHexString
Converts the provided bytes to a hexadecimalStringrepresentation. -
toHexString
Converts the provided bytes to a hexadecimalStringrepresentation.- Parameters:
aByteSeparator- The separator to separate two hex values from each other or null if no separator is to be used.aBytesPerLine- The number of bytes to put on one line before inserting a line separator.aBytes- The bytes for which to get the hexadecimalString.- Returns:
- The according
String.
-
toHexString
public static String toHexString(String aByteSeparator, int aBytesPerLine, boolean isPrefixBytes, byte... aBytes) Converts the provided bytes to a hexadecimalStringrepresentation.- Parameters:
aByteSeparator- The separator to separate two hex values from each other or null if no separator is to be used.aBytesPerLine- The number of bytes to put on one line before inserting a line separator.isPrefixBytes- When true, then0xis prefixed to the HEX values.aBytes- The bytes for which to get the hexadecimalString.- Returns:
- The according
String.
-
toHexString
Converts the provided bytes to a hexadecimalStringrepresentation. -
toHexString
Converts the provided bytes to a hexadecimalStringrepresentation. -
toHexString
Converts the provided bytes to a hexadecimalStringrepresentation. -
toHexString
Converts the provided bytes to a hexadecimalStringrepresentation. -
toHexString
Converts the provided bytes to a hexadecimalStringrepresentation.- Parameters:
aBytes- The bytes for which to get the hexadecimalString.aByteSeparator- The separator to separate two hex values from each other or null if no separator is to be used.aBytesPerLine- The number of bytes to put on one line before inserting a line separator.- Returns:
- The according
String.
-
toHexString
public static String toHexString(byte[] aBytes, String aByteSeparator, int aBytesPerLine, boolean isPrefixBytes) Converts the provided bytes to a hexadecimalStringrepresentation.- Parameters:
aBytes- The bytes for which to get the hexadecimalString.aByteSeparator- The separator to separate two hex values from each other or null if no separator is to be used.aBytesPerLine- The number of bytes to put on one line before inserting a line separator.isPrefixBytes- When true, then0xis prefixed to the HEX values.- Returns:
- The according
String.
-
toHexString
Converts the provided byte (in integer notation as ofInputStreamandOutputStreaminteger based byte operations)to a hexadecimalStringrepresentation. -
toHexString
Converts the provided byte (in integer notation as ofInputStreamandOutputStreaminteger based byte operations) to a hexadecimalStringrepresentation. -
toHexString
Converts the provided byte to a hexadecimalStringrepresentation. -
toHexString
Converts the provided byte to a hexadecimalStringrepresentation. -
toBoolean
Converts the given String to a boolean value. Accepted values for a "true" boolean are "1", "on", "yes", "true". Accepted values for a "false" boolean are "0", "off", "no", "false".- Parameters:
aValue- The text value to be tested whether it represents true or false.- Returns:
- True or false depending on the value passed.n
- Throws:
IllegalArgumentException- in case neither true nor false could be determined.
-
toMd5Hash
Generates a md5 hash of the given text.- Parameters:
aText- The text to be md5 hashed.- Returns:
- The md5 hashed text.
- Throws:
NoSuchAlgorithmException- thrown in case theMD5algorithm cannot be found on the classpath.
-
toScaled
public static double toScaled(double aValue, double aMin, double aMax) Scales the given value (which must be between 0 .. 1 to be between aMin .. aMax.- Parameters:
aValue- The value between 0 .. 1 to be scaled.aMin- The min value.aMax- The max value.- Returns:
- A value between aMin ... aMax.
-
sum
public static int sum(int... aSummands) Calculates the sum from the provided summands.- Parameters:
aSummands- The summands to be added up.- Returns:
- The sum of the provided summands.
-
toDouble
public static double toDouble(int aIntValue, double aMinDouble, double aMaxDouble) Converts the given integer value to a double of the given range.- Parameters:
aIntValue- The integer value which to convert accordinglyaMinDouble- The lower bounds of the double value.aMaxDouble- The upper bounds of the double value.- Returns:
- The accordingly converted value.
-
toDouble
public static double toDouble(long aLongValue, double aMinDouble, double aMaxDouble) Converts the given long value to a double of the given range.- Parameters:
aLongValue- The integer value which to convert accordinglyaMinDouble- The lower bounds of the double value.aMaxDouble- The upper bounds of the double value.- Returns:
- The accordingly converted value.
-
toHashCode
Calculates a Java-Version's implementation independent Hash-Code.- Parameters:
aValue- TheStringfrom which to get the Hash-Code.- Returns:
- The according Hash-Code.
-
toHashCodes
Creates a given number of IDs from the provided source text. Useful when creating numbers from a pass-phrase.- Parameters:
aSource- The source text from which to generate the IDs.aCount- The number of IDs to generate.- Returns:
- The IDs being generated.
-
toHashCodes
public static int[] toHashCodes(char[] aSource, int aCount) Creates a given number of IDs from the provided source text. Useful when creating numbers from a pass-phrase.- Parameters:
aSource- The source text from which to generate the IDs.aCount- The number of IDs to generate.- Returns:
- The IDs being generated.
-