public class PrimitiveConverter extends Object
| Modifier and Type | Method and Description |
|---|---|
static byte[] |
float32ToBytes(float val)
Convert a 32-bit floating point number to a byte array
|
static byte[] |
float64ToBytes(double val)
Convert a 64-bit floating point number to a byte array
|
static byte[] |
int16ToBytes(short val)
Convert a signed 16-bit integer to a byte array
|
static byte[] |
int32ToBytes(int val)
Convert a signed 32-bit integer to a byte array
|
static byte[] |
int32ToVariableBytes(int intValue)
Convert an signed 32-bit integer to a byte array.
|
static byte[] |
int64ToBytes(long val)
Convert a signed 64-byte integer to a byte array
|
static float |
toFloat32(byte[] bytes)
Convert a byte array to a 32-bit floating point number
|
static double |
toFloat64(byte[] bytes)
Convert a byte array to a 64-bit floating point number
|
static short |
toInt16(byte[] bytes)
Convert a byte array to a signed 16-bit integer
|
static short |
toInt16(byte[] bytes,
int offset)
Convert part of a byte array to an signed 16-bit integer
|
static int |
toInt32(byte[] bytes)
Convert a byte array to a signed 32-bit integer
|
static long |
toInt64(byte[] bytes)
Convert a byte array to a signed 64-bit integer
|
static int |
toUint16(byte[] bytes)
Convert a byte array to an unsigned 16-bit integer (int with range of uint16)
|
static long |
toUint32(byte[] bytes)
Convert a byte array to an unsigned 32-bit integer (long with range of uint32)
|
static int |
toUint8(byte[] bytes)
Convert a byte array to an unsigned 8-bit integer (int with range of uint8)
|
static byte[] |
uint16ToBytes(int val)
Convert an unsigned 16-bit unsigned integer (int with range of uint16) to a byte array
|
static byte[] |
uint32ToBytes(long val)
Convert an unsigned 32-bit unsigned integer (long with range of uint32) to a byte array
|
static byte[] |
uint32ToVariableBytes(long longValue)
Convert an unsigned 32-bit unsigned integer (long with range of uint32) to a byte array.
|
static byte[] |
uint8ToBytes(short val)
Convert an unsigned 8-bit unsigned integer (short with range of uint8) to a byte array
|
static byte[] |
uintToVariableBytesV6(long longValue)
Convert an unsigned 6 byte unsigned integer (long with range of uint48) to a byte array.
|
static long |
variableBytesToUint32(byte[] bytes)
Convert a variable length byte array to an unsigned 32-bit integer (long with range of uint32)
|
public static byte[] uint32ToVariableBytes(long longValue)
This is similar to uint32ToBytes, except that it only uses the minimum required number of bytes to represent the value. So if the value will fit into two bytes, the results will be only two bytes.
longValue - The unsigned 32-bit integer as longpublic static byte[] uintToVariableBytesV6(long longValue)
This only uses the minimum required number of bytes to represent the value. So if the value will fit into two bytes, the results will be only two bytes.
longValue - The unsigned integer as longpublic static int toInt32(byte[] bytes)
bytes - The array of length 1 - 4public static short toInt16(byte[] bytes)
bytes - The array of length 2public static short toInt16(byte[] bytes,
int offset)
bytes - The arrayoffset - the offset into the array where the conversion should startpublic static byte[] int16ToBytes(short val)
val - The short value (16-byte signed integer)public static byte[] int32ToBytes(int val)
val - The int value (32-byte signed integer)public static byte[] int32ToVariableBytes(int intValue)
This is similar to int32ToBytes, except that it only uses the minimum required number of bytes to represent the value. So if the value will fit into two bytes, the results will be only two bytes.
intValue - The signed 32-bit integerpublic static long toUint32(byte[] bytes)
bytes - The array of length 4public static long variableBytesToUint32(byte[] bytes)
bytes - The array of length 1-4public static byte[] uint32ToBytes(long val)
val - The unsigned 32-bit integer as longpublic static int toUint16(byte[] bytes)
bytes - The array of length 2public static byte[] uint16ToBytes(int val)
val - The unsigned 16-bit integer as intpublic static int toUint8(byte[] bytes)
bytes - The array of length 1public static byte[] uint8ToBytes(short val)
val - The unsigned 8-bit integer as shortpublic static long toInt64(byte[] bytes)
bytes - The array of length 8public static byte[] int64ToBytes(long val)
val - The long valuepublic static float toFloat32(byte[] bytes)
bytes - The array of length 4public static byte[] float32ToBytes(float val)
val - The float valuepublic static double toFloat64(byte[] bytes)
bytes - The array of length 8 or 4public static byte[] float64ToBytes(double val)
val - The double valueCopyright © 2020 West Ridge Systems. All rights reserved.