|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.neu.ccs.util.Conversions
Class Conversions contains type conversion utility
functions suitable for processing byte sequences and byte arrays
and for conversion of integral values (short, int, or long) to
floating values (float or double) that are between -1 and +1.
Class Conversions cannot be instantiated.
| Constructor Summary | |
private |
Conversions()
Private constructor to prevent instantiation. |
| Method Summary | |
static int |
bytesToIntHiLo(byte[] b)
Returns the int constructed from the byte array assuming that the byte order is high-to-low. |
static int |
bytesToIntHiLo(byte[] b,
int start)
Returns the int constructed from the byte array starting at the given start index and assuming that the byte order is high-to-low. |
static int |
bytesToIntHiLo(byte b0,
byte b1,
byte b2,
byte b3)
Returns the int constructed from the four given bytes assuming the byte order is high-to-low. |
static int |
bytesToIntLoHi(byte[] b)
Returns the int constructed from the byte array assuming that the byte order is low-to-high. |
static int |
bytesToIntLoHi(byte[] b,
int start)
Returns the int constructed from the byte array starting at the given start index and assuming that the byte order is low-to-high. |
static int |
bytesToIntLoHi(byte b0,
byte b1,
byte b2,
byte b3)
Returns the int constructed from the four given bytes assuming the byte order is low-to-high. |
static long |
bytesToLongHiLo(byte[] b)
Returns the long constructed from the byte array assuming that the byte order is high-to-low. |
static long |
bytesToLongHiLo(byte[] b,
int start)
Returns the long constructed from the byte array starting at the given start index and assuming that the byte order is high-to-low. |
static long |
bytesToLongHiLo(byte b0,
byte b1,
byte b2,
byte b3,
byte b4,
byte b5,
byte b6,
byte b7)
Returns the long constructed from the eight given bytes assuming the byte order is high-to-low. |
static long |
bytesToLongLoHi(byte[] b)
Returns the long constructed from the byte array assuming that the byte order is low-to-high. |
static long |
bytesToLongLoHi(byte[] b,
int start)
Returns the long constructed from the byte array starting at the given start index and assuming that the byte order is low-to-high. |
static long |
bytesToLongLoHi(byte b0,
byte b1,
byte b2,
byte b3,
byte b4,
byte b5,
byte b6,
byte b7)
Returns the long constructed from the eight given bytes assuming the byte order is low-to-high. |
static short |
bytesToShortHiLo(byte[] b)
Returns the short constructed from the byte array assuming that the byte order is high-to-low. |
static short |
bytesToShortHiLo(byte[] b,
int start)
Returns the short constructed from the byte array starting at the given start index and assuming that the byte order is high-to-low. |
static short |
bytesToShortHiLo(byte b0,
byte b1)
Returns the short constructed from the pair of bytes assuming b0 is the high byte
and
b1 is the low byte. |
static short |
bytesToShortLoHi(byte[] b)
Returns the short constructed from the byte array assuming that the byte order is low-to-high. |
static short |
bytesToShortLoHi(byte[] b,
int start)
Returns the short constructed from the byte array starting at the given start index and assuming that the byte order is low-to-high. |
static short |
bytesToShortLoHi(byte b0,
byte b1)
Returns the short constructed from the pair of bytes assuming b0 is the low byte
and
b1 is the high byte. |
static int |
doubleToInt(double x)
If the given double x is between -1 and +1,
then returns the value x * Integer.MAX_VALUE
rounded to the nearest int. |
static long |
doubleToLong(double x)
If the given double x is between -1 and +1,
then returns the value x * Long.MAX_VALUE
rounded to the nearest long. |
static short |
doubleToShort(double x)
If the given double x is between -1 and +1,
then returns the value x * Short.MAX_VALUE
rounded to the nearest short. |
static int |
floatToInt(float x)
If the given float x is between -1 and +1,
then returns the value x * Integer.MAX_VALUE
rounded to the nearest int. |
static long |
floatToLong(float x)
If the given float x is between -1 and +1,
then returns the value x * Long.MAX_VALUE
rounded to the nearest long. |
static short |
floatToShort(float x)
If the given float x is between -1 and +1,
then returns the value x * Short.MAX_VALUE
rounded to the nearest short. |
static byte[] |
intToBytesHiLo(int s)
Returns an array of bytes of size 4 with the 4 bytes of the given int in high-to-low order. |
static byte[] |
intToBytesLoHi(int s)
Returns an array of bytes of size 4 with the 4 bytes of the given int in low-to-high order. |
static double |
intToDouble(int s)
Returns the double between -1 and +1 calculated by dividing the given int by Integer.MAX_VALUE. |
static float |
intToFloat(int s)
Returns the float between -1 and +1 calculated by dividing the given int by Integer.MAX_VALUE. |
static byte[] |
longToBytesHiLo(long s)
Returns an array of bytes of size 8 with the 8 bytes of the given long in high-to-low order. |
static byte[] |
longToBytesLoHi(long s)
Returns an array of bytes of size 8 with the 8 bytes of the given long in low-to-high order. |
static double |
longToDouble(long s)
Returns the double between -1 and +1 calculated by dividing the given long by Long.MAX_VALUE. |
static float |
longToFloat(long s)
Returns the float between -1 and +1 calculated by dividing the given long by Long.MAX_VALUE. |
static byte[] |
shortToBytesHiLo(short s)
Returns an array of bytes of size 2 with the 2 bytes of the given short in high-to-low order. |
static byte[] |
shortToBytesLoHi(short s)
Returns an array of bytes of size 2 with the 2 bytes of the given short in low-to-high order. |
static double |
shortToDouble(short s)
Returns the double between -1 and +1 calculated by dividing the given short by Short.MAX_VALUE. |
static float |
shortToFloat(short s)
Returns the float between -1 and +1 calculated by dividing the given short by Short.MAX_VALUE. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
private Conversions()
| Method Detail |
public static short bytesToShortLoHi(byte[] b)
Returns the short constructed from the byte array assuming that the byte order is low-to-high.
If the byte array is null or has
length 0, return 0.
If the byte array does not have enough items then assume the missing items are 0.
Ignore items in the byte array that are not in the range: 0 to 1.
b - the byte array
bytesToShortLoHi(byte[], int),
bytesToShortLoHi(byte, byte),
bytesToShortHiLo(byte[]),
bytesToShortHiLo(byte[], int),
bytesToShortHiLo(byte, byte)
public static short bytesToShortLoHi(byte[] b,
int start)
Returns the short constructed from the byte array starting at the given start index and assuming that the byte order is low-to-high.
If the byte array is null or start
is not a valid index into the byte array, return 0.
If the byte array does not have enough items from start onward then assume the missing items are 0.
Ignore items in the byte array that are not in the range: start to (start + 1).
b - the byte arraystart - the start index
bytesToShortLoHi(byte[]),
bytesToShortLoHi(byte, byte),
bytesToShortHiLo(byte[]),
bytesToShortHiLo(byte[], int),
bytesToShortHiLo(byte, byte)
public static short bytesToShortLoHi(byte b0,
byte b1)
Returns the short constructed from the pair of bytes assuming
b0 is the low byte
and
b1 is the high byte.
b0 - the low byteb1 - the high byte
bytesToShortLoHi(byte[]),
bytesToShortLoHi(byte[], int),
bytesToShortHiLo(byte[]),
bytesToShortHiLo(byte[], int),
bytesToShortHiLo(byte, byte)public static short bytesToShortHiLo(byte[] b)
Returns the short constructed from the byte array assuming that the byte order is high-to-low.
If the byte array is null or has
length 0, return 0.
If the byte array does not have enough items then assume the missing items are 0.
Ignore items in the byte array that are not in the range: 0 to 1.
b - the byte array
bytesToShortLoHi(byte[]),
bytesToShortLoHi(byte[], int),
bytesToShortLoHi(byte, byte),
bytesToShortHiLo(byte[], int),
bytesToShortHiLo(byte, byte)
public static short bytesToShortHiLo(byte[] b,
int start)
Returns the short constructed from the byte array starting at the given start index and assuming that the byte order is high-to-low.
If the byte array is null or start
is not a valid index into the byte array, return 0.
If the byte array does not have enough items from start onward then assume the missing items are 0.
Ignore items in the byte array that are not in the range: start to (start + 1).
b - the byte arraystart - the start index
bytesToShortLoHi(byte[]),
bytesToShortLoHi(byte[], int),
bytesToShortLoHi(byte, byte),
bytesToShortHiLo(byte[]),
bytesToShortHiLo(byte, byte)
public static short bytesToShortHiLo(byte b0,
byte b1)
Returns the short constructed from the pair of bytes assuming
b0 is the high byte
and
b1 is the low byte.
b0 - the high byteb1 - the low byte
bytesToShortLoHi(byte[]),
bytesToShortLoHi(byte[], int),
bytesToShortLoHi(byte, byte),
bytesToShortHiLo(byte[]),
bytesToShortHiLo(byte[], int)public static byte[] shortToBytesLoHi(short s)
Returns an array of bytes of size 2 with the 2 bytes of the given short in low-to-high order.
s - the short that defines the bytes
shortToBytesHiLo(short)public static byte[] shortToBytesHiLo(short s)
Returns an array of bytes of size 2 with the 2 bytes of the given short in high-to-low order.
s - the short that defines the bytes
shortToBytesLoHi(short)public static int bytesToIntLoHi(byte[] b)
Returns the int constructed from the byte array assuming that the byte order is low-to-high.
If the byte array is null or has
length 0, return 0.
If the byte array does not have enough items then assume the missing items are 0.
Ignore items in the byte array that are not in the range: 0 to 3.
b - the byte array
bytesToIntLoHi(byte[], int),
bytesToIntLoHi(byte, byte, byte, byte),
bytesToIntHiLo(byte[]),
bytesToIntHiLo(byte[], int),
bytesToIntHiLo(byte, byte, byte, byte)
public static int bytesToIntLoHi(byte[] b,
int start)
Returns the int constructed from the byte array starting at the given start index and assuming that the byte order is low-to-high.
If the byte array is null or start
is not a valid index into the byte array, return 0.
If the byte array does not have enough items from start onward then assume the missing items are 0.
Ignore items in the byte array that are not in the range: start to (start + 3).
b - the byte arraystart - the start index
bytesToIntLoHi(byte[]),
bytesToIntLoHi(byte, byte, byte, byte),
bytesToIntHiLo(byte[]),
bytesToIntHiLo(byte[], int),
bytesToIntHiLo(byte, byte, byte, byte)
public static int bytesToIntLoHi(byte b0,
byte b1,
byte b2,
byte b3)
Returns the int constructed from the four given bytes assuming the byte order is low-to-high.
b0 - the lowest byteb1 - the next byteb2 - the next byteb3 - the next byte
bytesToIntLoHi(byte[]),
bytesToIntLoHi(byte[], int),
bytesToIntHiLo(byte[]),
bytesToIntHiLo(byte[], int),
bytesToIntHiLo(byte, byte, byte, byte)public static int bytesToIntHiLo(byte[] b)
Returns the int constructed from the byte array assuming that the byte order is high-to-low.
If the byte array is null or has
length 0, return 0.
If the byte array does not have enough items then assume the missing items are 0.
Ignore items in the byte array that are not in the range: 0 to 3.
b - the byte array
bytesToIntLoHi(byte[]),
bytesToIntLoHi(byte[], int),
bytesToIntLoHi(byte, byte, byte, byte),
bytesToIntHiLo(byte[], int),
bytesToIntHiLo(byte, byte, byte, byte)
public static int bytesToIntHiLo(byte[] b,
int start)
Returns the int constructed from the byte array starting at the given start index and assuming that the byte order is high-to-low.
If the byte array is null or start
is not a valid index into the byte array, return 0.
If the byte array does not have enough items from start onward then assume the missing items are 0.
Ignore items in the byte array that are not in the range: start to (start + 3).
b - the byte arraystart - the start index
bytesToIntLoHi(byte[]),
bytesToIntLoHi(byte[], int),
bytesToIntLoHi(byte, byte, byte, byte),
bytesToIntHiLo(byte[]),
bytesToIntHiLo(byte, byte, byte, byte)
public static int bytesToIntHiLo(byte b0,
byte b1,
byte b2,
byte b3)
Returns the int constructed from the four given bytes assuming the byte order is high-to-low.
b0 - the highest byteb1 - the next byteb2 - the next byteb3 - the next byte
bytesToIntLoHi(byte[]),
bytesToIntLoHi(byte[], int),
bytesToIntLoHi(byte, byte, byte, byte),
bytesToIntHiLo(byte[]),
bytesToIntHiLo(byte[], int)public static byte[] intToBytesLoHi(int s)
Returns an array of bytes of size 4 with the 4 bytes of the given int in low-to-high order.
s - the int that defines the bytes
intToBytesHiLo(int)public static byte[] intToBytesHiLo(int s)
Returns an array of bytes of size 4 with the 4 bytes of the given int in high-to-low order.
s - the int that defines the bytes
intToBytesLoHi(int)public static long bytesToLongLoHi(byte[] b)
Returns the long constructed from the byte array assuming that the byte order is low-to-high.
If the byte array is null or has
length 0, return 0.
If the byte array does not have enough items then assume the missing items are 0.
Ignore items in the byte array that are not in the range: 0 to 7.
b - the byte array
bytesToLongLoHi(byte[], int),
bytesToLongLoHi(byte, byte, byte, byte, byte, byte, byte, byte),
bytesToLongHiLo(byte[]),
bytesToLongHiLo(byte[], int),
bytesToLongHiLo(byte, byte, byte, byte, byte, byte, byte, byte)
public static long bytesToLongLoHi(byte[] b,
int start)
Returns the long constructed from the byte array starting at the given start index and assuming that the byte order is low-to-high.
If the byte array is null or start
is not a valid index into the byte array, return 0.
If the byte array does not have enough items from start onward then assume the missing items are 0.
Ignore items in the byte array that are not in the range: start to (start + 7).
b - the byte arraystart - the start index
bytesToLongLoHi(byte[]),
bytesToLongLoHi(byte, byte, byte, byte, byte, byte, byte, byte),
bytesToLongHiLo(byte[]),
bytesToLongHiLo(byte[], int),
bytesToLongHiLo(byte, byte, byte, byte, byte, byte, byte, byte)
public static long bytesToLongLoHi(byte b0,
byte b1,
byte b2,
byte b3,
byte b4,
byte b5,
byte b6,
byte b7)
Returns the long constructed from the eight given bytes assuming the byte order is low-to-high.
b0 - the lowest byteb1 - the next byteb2 - the next byteb3 - the next byteb4 - the next byteb5 - the next byteb6 - the next byteb7 - the next byte
bytesToLongLoHi(byte[]),
bytesToLongLoHi(byte[], int),
bytesToLongHiLo(byte[]),
bytesToLongHiLo(byte[], int),
bytesToLongHiLo(byte, byte, byte, byte, byte, byte, byte, byte)public static long bytesToLongHiLo(byte[] b)
Returns the long constructed from the byte array assuming that the byte order is high-to-low.
If the byte array is null or has
length 0, return 0.
If the byte array does not have enough items then assume the missing items are 0.
Ignore items in the byte array that are not in the range: 0 to 7.
b - the byte array
bytesToLongLoHi(byte[]),
bytesToLongLoHi(byte[], int),
bytesToLongLoHi(byte, byte, byte, byte, byte, byte, byte, byte),
bytesToLongHiLo(byte[], int),
bytesToLongHiLo(byte, byte, byte, byte, byte, byte, byte, byte)
public static long bytesToLongHiLo(byte[] b,
int start)
Returns the long constructed from the byte array starting at the given start index and assuming that the byte order is high-to-low.
If the byte array is null or start
is not a valid index into the byte array, return 0.
If the byte array does not have enough items from start onward then assume the missing items are 0.
Ignore items in the byte array that are not in the range: start to (start + 7).
b - the byte arraystart - the start index
bytesToLongLoHi(byte[]),
bytesToLongLoHi(byte[], int),
bytesToLongLoHi(byte, byte, byte, byte, byte, byte, byte, byte),
bytesToLongHiLo(byte[]),
bytesToLongHiLo(byte, byte, byte, byte, byte, byte, byte, byte)
public static long bytesToLongHiLo(byte b0,
byte b1,
byte b2,
byte b3,
byte b4,
byte b5,
byte b6,
byte b7)
Returns the long constructed from the eight given bytes assuming the byte order is high-to-low.
b0 - the highest byteb1 - the next byteb2 - the next byteb3 - the next byteb4 - the next byteb5 - the next byteb6 - the next byteb7 - the next byte
bytesToLongLoHi(byte[]),
bytesToLongLoHi(byte[], int),
bytesToLongLoHi(byte, byte, byte, byte, byte, byte, byte, byte),
bytesToLongHiLo(byte[]),
bytesToLongHiLo(byte[], int)public static byte[] longToBytesLoHi(long s)
Returns an array of bytes of size 8 with the 8 bytes of the given long in low-to-high order.
s - the long that defines the bytes
longToBytesHiLo(long)public static byte[] longToBytesHiLo(long s)
Returns an array of bytes of size 8 with the 8 bytes of the given long in high-to-low order.
s - the long that defines the bytes
longToBytesLoHi(long)public static float shortToFloat(short s)
Returns the float between -1 and +1 calculated by dividing
the given short by Short.MAX_VALUE.
The short Short.MIN_VALUE is treated as a special
case. For this value, the method returns -1.
s - the short to convert to a float between -1 and +1
public static float intToFloat(int s)
Returns the float between -1 and +1 calculated by dividing
the given int by Integer.MAX_VALUE.
The int Integer.MIN_VALUE is treated as a special
case. For this value, the method returns -1.
The method intends to map an int to a float between -1 and +1.
Its value is quite different from that of the following method in
class Float:
public static float intBitsToFloat(int bits)
s - the int to convert to a float between -1 and +1
Float.intBitsToFloat(int)public static float longToFloat(long s)
Returns the float between -1 and +1 calculated by dividing
the given long by Long.MAX_VALUE.
The long Long.MIN_VALUE is treated as a special
case. For this value, the method returns -1.
s - the long to convert to a float between -1 and +1
public static short floatToShort(float x)
If the given float x is between -1 and +1,
then returns the value x * Short.MAX_VALUE
rounded to the nearest short.
If the given float x is greater than or equal to +1,
then returns Short.MAX_VALUE.
If the given float x is less than or equal to -1,
then returns -Short.MAX_VALUE.
If the given float is NaN, returns 0.
x - the float between -1 and +1 to convert to a short
public static int floatToInt(float x)
If the given float x is between -1 and +1,
then returns the value x * Integer.MAX_VALUE
rounded to the nearest int.
If the given float x is greater than or equal to +1,
then returns Integer.MAX_VALUE.
If the given float x is less than or equal to -1,
then returns -Integer.MAX_VALUE.
If the given float is NaN, returns 0.
The method intends to map a float between -1 and +1 to an int.
Its value is quite different from that of the following methods in
class Float:
public static int floatToIntBits(float value)public static int floatToRawIntBits(float value)
x - the float between -1 and +1 to convert to an int
Float.floatToIntBits(float),
Float.floatToRawIntBits(float)public static long floatToLong(float x)
If the given float x is between -1 and +1,
then returns the value x * Long.MAX_VALUE
rounded to the nearest long.
If the given float x is greater than or equal to +1,
then returns Long.MAX_VALUE.
If the given float x is less than or equal to -1,
then returns -Long.MAX_VALUE.
If the given float is NaN, returns 0.
x - the float between -1 and +1 to convert to a long
public static double shortToDouble(short s)
Returns the double between -1 and +1 calculated by dividing
the given short by Short.MAX_VALUE.
The short Short.MIN_VALUE is treated as a special
case. For this value, the method returns -1.
s - the short to convert to a double between -1 and +1
public static double intToDouble(int s)
Returns the double between -1 and +1 calculated by dividing
the given int by Integer.MAX_VALUE.
The int Integer.MIN_VALUE is treated as a special
case. For this value, the method returns -1.
s - the int to convert to a double between -1 and +1
public static double longToDouble(long s)
Returns the double between -1 and +1 calculated by dividing
the given long by Long.MAX_VALUE.
The long Long.MIN_VALUE is treated as a special
case. For this value, the method returns -1.
The method intends to map a long to a double between -1 and +1.
Its value is quite different from that of the following method in
class Double:
public static double longBitsToDouble(long bits)
s - the long to convert to a double between -1 and +1
Double.longBitsToDouble(long)public static short doubleToShort(double x)
If the given double x is between -1 and +1,
then returns the value x * Short.MAX_VALUE
rounded to the nearest short.
If the given double x is greater than or equal to +1,
then returns Short.MAX_VALUE.
If the given double x is less than or equal to -1,
then returns -Short.MAX_VALUE.
If the given double is NaN, returns 0.
x - the double between -1 and +1 to convert to a short
public static int doubleToInt(double x)
If the given double x is between -1 and +1,
then returns the value x * Integer.MAX_VALUE
rounded to the nearest int.
If the given double x is greater than or equal to +1,
then returns Integer.MAX_VALUE.
If the given double x is less than or equal to -1,
then returns -Integer.MAX_VALUE.
If the given double is NaN, returns 0.
x - the double between -1 and +1 to convert to an int
public static long doubleToLong(double x)
If the given double x is between -1 and +1,
then returns the value x * Long.MAX_VALUE
rounded to the nearest long.
If the given double x is greater than or equal to +1,
then returns Long.MAX_VALUE.
If the given double x is less than or equal to -1,
then returns -Long.MAX_VALUE.
If the given double is NaN, returns 0.
The method intends to map a double between -1 and +1 to a long.
Its value is quite different from that of the following methods in
class Double:
public static long doubleToLongBits(double value)public static long doubleToRawLongBits(double value)
x - the double between -1 and +1 to convert to a long
Double.doubleToLongBits(double),
Double.doubleToRawLongBits(double)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||