public final class Bytes extends Object
byte
s
and byte
arrays.Modifier and Type | Method and Description |
---|---|
static byte[] |
fromDouble(double value,
boolean little)
Translates the
double value into an array of eight byte s. |
static byte[] |
fromDoubles(double[] values,
boolean little)
Translates an array of
double values into an array of byte
values. |
static byte[] |
fromFloat(float value,
boolean little)
Translates the
float value into an array of four byte s. |
static byte[] |
fromFloats(float[] values,
boolean little)
Translates an array of
float values into an array of byte
values. |
static byte[] |
fromInt(int value,
boolean little)
Translates the
int value into an array of four byte s. |
static byte[] |
fromInts(int[] values,
boolean little)
Translates an array of
int values into an array of byte
values. |
static byte[] |
fromLong(long value,
boolean little)
Translates the
long value into an array of eight byte s. |
static byte[] |
fromLongs(long[] values,
boolean little)
Translates an array of
long values into an array of byte
values. |
static byte[] |
fromShort(short value,
boolean little)
Translates the
short value into an array of two byte s. |
static byte[] |
fromShorts(short[] values,
boolean little)
Translates an array of
short values into an array of byte
values. |
static Object |
makeArray(byte[] b,
int bpp,
boolean fp,
boolean little)
Converts a
byte array to the appropriate 1D primitive type array. |
static Object |
makeArray2D(byte[] b,
int bpp,
boolean fp,
boolean little,
int height)
Converts a
byte array to the appropriate 2D primitive type array. |
static byte[] |
makeSigned(byte[] b) |
static int[] |
makeSigned(int[] i) |
static short[] |
makeSigned(short[] s) |
static double[] |
normalize(double[] data)
Normalize the given
double array so that the minimum value maps to
0.0 and the maximum value maps to 1.0. |
static float[] |
normalize(float[] data)
Normalize the given
float array so that the minimum value maps to
0.0 and the maximum value maps to 1.0. |
static char |
swap(char x) |
static double |
swap(double x) |
static float |
swap(float x) |
static int |
swap(int x) |
static long |
swap(long x) |
static short |
swap(short x) |
static double |
toDouble(byte[] bytes,
boolean little)
Translates up to the first 8 bytes of a
byte array to a
double . |
static double |
toDouble(byte[] bytes,
int off,
boolean little)
Translates up to the first 8 bytes of a
byte array beyond the given
offset to a double . |
static double |
toDouble(byte[] bytes,
int off,
int len,
boolean little)
Translates up to the first
len bytes of a byte array beyond
the given offset to a double . |
static double |
toDouble(short[] bytes,
boolean little)
Translates up to the first 8 bytes of a
byte array to a
double . |
static double |
toDouble(short[] bytes,
int off,
boolean little)
Translates up to the first 8 bytes of a
byte array beyond the given
offset to a double . |
static double |
toDouble(short[] bytes,
int off,
int len,
boolean little)
Translates up to the first
len bytes of a byte array beyond
the given offset to a double . |
static float |
toFloat(byte[] bytes,
boolean little)
Translates up to the first 4 bytes of a
byte array to a
float . |
static float |
toFloat(byte[] bytes,
int off,
boolean little)
Translates up to the first 4 bytes of a
byte array beyond a given
offset to a float . |
static float |
toFloat(byte[] bytes,
int off,
int len,
boolean little)
Translates up to the first
len bytes of a byte array beyond
the given offset to a float . |
static float |
toFloat(short[] bytes,
boolean little)
Translates up to the first 4 bytes of a
byte array to a
float . |
static float |
toFloat(short[] bytes,
int off,
boolean little)
Translates up to the first 4 bytes of a
byte array beyond a given
offset to a float . |
static float |
toFloat(short[] bytes,
int off,
int len,
boolean little)
Translates up to the first
len bytes of a byte array beyond
a given offset to a float . |
static int |
toInt(byte[] bytes,
boolean little)
Translates up to the first 4 bytes of a
byte array to an
int . |
static int |
toInt(byte[] bytes,
int off,
boolean little)
Translates up to the first 4 bytes of a
byte array beyond the given
offset to an int . |
static int |
toInt(byte[] bytes,
int off,
int len,
boolean little)
Translates up to the first
len bytes of a byte array beyond
the given offset to an int . |
static int |
toInt(short[] bytes,
boolean little)
Translates up to the first 4 bytes of a
byte array to an
int . |
static int |
toInt(short[] bytes,
int off,
boolean little)
Translates up to the first 4 bytes of a
byte array beyond the given
offset to an int . |
static int |
toInt(short[] bytes,
int off,
int len,
boolean little)
Translates up to the first
len bytes of a byte array beyond
the given offset to an int . |
static long |
toLong(byte[] bytes,
boolean little)
Translates up to the first 8 bytes of a
byte array to a
long . |
static long |
toLong(byte[] bytes,
int off,
boolean little)
Translates up to the first 8 bytes of a
byte array beyond the given
offset to a long . |
static long |
toLong(byte[] bytes,
int off,
int len,
boolean little)
Translates up to the first
len bytes of a byte array beyond
the given offset to a long . |
static long |
toLong(short[] bytes,
boolean little)
Translates up to the first 8 bytes of a
byte array to a
long . |
static long |
toLong(short[] bytes,
int off,
boolean little)
Translates up to the first 8 bytes of a
byte array beyond the given
offset to a long . |
static long |
toLong(short[] bytes,
int off,
int len,
boolean little)
Translates up to the first
len bytes of a byte array beyond
the given offset to a long . |
static short |
toShort(byte[] bytes,
boolean little)
Translates up to the first 2 bytes of a
byte array to a
short . |
static short |
toShort(byte[] bytes,
int off,
boolean little)
Translates up to the first 2 bytes of a
byte array beyond the given
offset to a short . |
static short |
toShort(byte[] bytes,
int off,
int len,
boolean little)
Translates up to the first
len bytes of a byte array beyond
the given offset to a short . |
static short |
toShort(short[] bytes,
boolean little)
Translates up to the first 2 bytes of a
byte array to a
short . |
static short |
toShort(short[] bytes,
int off,
boolean little)
Translates up to the first 2 bytes of a
byte array beyond the given
offset to a short . |
static short |
toShort(short[] bytes,
int off,
int len,
boolean little)
Translates up to the first
len bytes of a byte array beyond
the given offset to a short . |
static void |
unpack(long value,
byte[] buf,
int ndx,
int nBytes,
boolean little)
Translates
nBytes of the given long and places the result
in the given byte array. |
public static short toShort(byte[] bytes, int off, int len, boolean little)
len
bytes of a byte
array beyond
the given offset to a short
. If there are fewer than len
bytes available, the MSBs are all assumed to be zero (regardless of
endianness).public static short toShort(byte[] bytes, int off, boolean little)
byte
array beyond the given
offset to a short
. If there are fewer than 2 bytes available the
MSBs are all assumed to be zero (regardless of endianness).public static short toShort(byte[] bytes, boolean little)
byte
array to a
short
. If there are fewer than 2 bytes available, the MSBs are all
assumed to be zero (regardless of endianness).public static short toShort(short[] bytes, int off, int len, boolean little)
len
bytes of a byte
array beyond
the given offset to a short
. If there are fewer than len
bytes available, the MSBs are all assumed to be zero (regardless of
endianness).public static short toShort(short[] bytes, int off, boolean little)
byte
array beyond the given
offset to a short
. If there are fewer than 2 bytes available, the
MSBs are all assumed to be zero (regardless of endianness).public static short toShort(short[] bytes, boolean little)
byte
array to a
short
. If there are fewer than 2 bytes available, the MSBs are all
assumed to be zero (regardless of endianness).public static int toInt(byte[] bytes, int off, int len, boolean little)
len
bytes of a byte
array beyond
the given offset to an int
. If there are fewer than len
bytes available, the MSBs are all assumed to be zero (regardless of
endianness).public static int toInt(byte[] bytes, int off, boolean little)
byte
array beyond the given
offset to an int
. If there are fewer than 4 bytes available, the
MSBs are all assumed to be zero (regardless of endianness).public static int toInt(byte[] bytes, boolean little)
byte
array to an
int
. If there are fewer than 4 bytes available, the MSBs are all
assumed to be zero (regardless of endianness).public static int toInt(short[] bytes, int off, int len, boolean little)
len
bytes of a byte
array beyond
the given offset to an int
. If there are fewer than len
bytes available, the MSBs are all assumed to be zero (regardless of
endianness).public static int toInt(short[] bytes, int off, boolean little)
byte
array beyond the given
offset to an int
. If there are fewer than 4 bytes available, the
MSBs are all assumed to be zero (regardless of endianness).public static int toInt(short[] bytes, boolean little)
byte
array to an
int
. If there are fewer than 4 bytes available, the MSBs are all
assumed to be zero (regardless of endianness).public static float toFloat(byte[] bytes, int off, int len, boolean little)
len
bytes of a byte
array beyond
the given offset to a float
. If there are fewer than len
bytes available, the MSBs are all assumed to be zero (regardless of
endianness).public static float toFloat(byte[] bytes, int off, boolean little)
byte
array beyond a given
offset to a float
. If there are fewer than 4 bytes available, the
MSBs are all assumed to be zero (regardless of endianness).public static float toFloat(byte[] bytes, boolean little)
byte
array to a
float
. If there are fewer than 4 bytes available, the MSBs are all
assumed to be zero (regardless of endianness).public static float toFloat(short[] bytes, int off, int len, boolean little)
len
bytes of a byte
array beyond
a given offset to a float
. If there are fewer than len
bytes available, the MSBs are all assumed to be zero (regardless of
endianness).public static float toFloat(short[] bytes, int off, boolean little)
byte
array beyond a given
offset to a float
. If there are fewer than 4 bytes available, the
MSBs are all assumed to be zero (regardless of endianness).public static float toFloat(short[] bytes, boolean little)
byte
array to a
float
. If there are fewer than 4 bytes available, the MSBs are all
assumed to be zero (regardless of endianness).public static long toLong(byte[] bytes, int off, int len, boolean little)
len
bytes of a byte
array beyond
the given offset to a long
. If there are fewer than len
bytes available, the MSBs are all assumed to be zero (regardless of
endianness).public static long toLong(byte[] bytes, int off, boolean little)
byte
array beyond the given
offset to a long
. If there are fewer than 8 bytes available, the
MSBs are all assumed to be zero (regardless of endianness).public static long toLong(byte[] bytes, boolean little)
byte
array to a
long
. If there are fewer than 8 bytes available, the MSBs are all
assumed to be zero (regardless of endianness).public static long toLong(short[] bytes, int off, int len, boolean little)
len
bytes of a byte
array beyond
the given offset to a long
. If there are fewer than len
bytes available, the MSBs are all assumed to be zero (regardless of
endianness).public static long toLong(short[] bytes, int off, boolean little)
byte
array beyond the given
offset to a long
. If there are fewer than 8 bytes available, the
MSBs are all assumed to be zero (regardless of endianness).public static long toLong(short[] bytes, boolean little)
byte
array to a
long
. If there are fewer than 8 bytes available, the MSBs are all
assumed to be zero (regardless of endianness).public static double toDouble(byte[] bytes, int off, int len, boolean little)
len
bytes of a byte
array beyond
the given offset to a double
. If there are fewer than len
bytes available, the MSBs are all assumed to be zero (regardless of
endianness).public static double toDouble(byte[] bytes, int off, boolean little)
byte
array beyond the given
offset to a double
. If there are fewer than 8 bytes available, the
MSBs are all assumed to be zero (regardless of endianness).public static double toDouble(byte[] bytes, boolean little)
byte
array to a
double
. If there are fewer than 8 bytes available, the MSBs are all
assumed to be zero (regardless of endianness).public static double toDouble(short[] bytes, int off, int len, boolean little)
len
bytes of a byte
array beyond
the given offset to a double
. If there are fewer than len
bytes available, the MSBs are all assumed to be zero (regardless of
endianness).public static double toDouble(short[] bytes, int off, boolean little)
byte
array beyond the given
offset to a double
. If there are fewer than 8 bytes available, the
MSBs are all assumed to be zero (regardless of endianness).public static double toDouble(short[] bytes, boolean little)
byte
array to a
double
. If there are fewer than 8 bytes available, the MSBs are all
assumed to be zero (regardless of endianness).public static byte[] fromShort(short value, boolean little)
short
value into an array of two byte
s.public static byte[] fromInt(int value, boolean little)
int
value into an array of four byte
s.public static byte[] fromFloat(float value, boolean little)
float
value into an array of four byte
s.public static byte[] fromLong(long value, boolean little)
long
value into an array of eight byte
s.public static byte[] fromDouble(double value, boolean little)
double
value into an array of eight byte
s.public static byte[] fromShorts(short[] values, boolean little)
short
values into an array of byte
values.public static byte[] fromInts(int[] values, boolean little)
int
values into an array of byte
values.public static byte[] fromFloats(float[] values, boolean little)
float
values into an array of byte
values.public static byte[] fromLongs(long[] values, boolean little)
long
values into an array of byte
values.public static byte[] fromDoubles(double[] values, boolean little)
double
values into an array of byte
values.public static void unpack(long value, byte[] buf, int ndx, int nBytes, boolean little)
nBytes
of the given long
and places the result
in the given byte
array.IllegalArgumentException
- if the specified indices fall outside the
bufferpublic static Object makeArray(byte[] b, int bpp, boolean fp, boolean little)
byte
array to the appropriate 1D primitive type array.b
- Byte array to convert.bpp
- Denotes the number of bytes in the returned primitive type (e.g.
if bpp == 2, we should return an array of type short
).fp
- If set and bpp == 4 or bpp == 8, then return float
s or
double
s.little
- Whether byte
array is in little-endian order.public static Object makeArray2D(byte[] b, int bpp, boolean fp, boolean little, int height)
byte
array to the appropriate 2D primitive type array.b
- Byte array to convert.bpp
- Denotes the number of bytes in the returned primitive type (e.g.
if bpp == 2, we should return an array of type short
).fp
- If set and bpp == 4 or bpp == 8, then return float
s or
double
s.little
- Whether byte
array is in little-endian order.height
- The height of the output primitive array (2nd dim length).IllegalArgumentException
- if input byte
array does not
divide evenly into height piecespublic static short swap(short x)
public static char swap(char x)
public static int swap(int x)
public static long swap(long x)
public static float swap(float x)
public static double swap(double x)
public static float[] normalize(float[] data)
float
array so that the minimum value maps to
0.0 and the maximum value maps to 1.0.public static double[] normalize(double[] data)
double
array so that the minimum value maps to
0.0 and the maximum value maps to 1.0.public static byte[] makeSigned(byte[] b)
public static short[] makeSigned(short[] s)
public static int[] makeSigned(int[] i)
Copyright © 2015–2022 SciJava. All rights reserved.