Package rma.util
Class ByteConversion
java.lang.Object
rma.util.ByteConversion
Class to convert between bytes and other primatives
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Colorbytes2color(byte[] dataIn, int offset) convert an array of bytes into aColorstatic intbytes2int(byte[] dataIn, int offset) convert an array of bytes to an intstatic longbytes2long(byte[] dataIn, int offset) Convert an array of bytes to a longstatic shortbytes2short(byte[] dataIn, int offset) convert bytes into a shortstatic voidcolor2bytes(Color color, byte[] dataOut, int offset) convert aColorto a array of bytesstatic voidint2bytes(int intIn, byte[] bytesOut, int offset) convert an int to bytesstatic voidlong2bytes(long longIn, byte[] bytesOut, int offset) convert a long to an array of bytesstatic voidshort2bytes(short shortIn, byte[] bytesOut, int offset) convert a short to an array of bytesstatic longunsignedByte(byte x) take a byte and return the unsigned version
-
Constructor Details
-
ByteConversion
public ByteConversion()
-
-
Method Details
-
color2bytes
convert aColorto a array of bytes- Parameters:
color- the colordataOut- the byte array to store into. Needs to be at least offset + 3 in lengthoffset- the offset into dataOut to store the color byte info
-
bytes2color
convert an array of bytes into aColor- Parameters:
dataIn- the byte array that hold theColorinfo. must be at least offset + 3 in lengthoffset- the offset into dataIn where theColorinfo is- Returns:
- the new
Color
-
short2bytes
public static void short2bytes(short shortIn, byte[] bytesOut, int offset) convert a short to an array of bytes- Parameters:
shortIn- the short to convert to bytesbytesOut- the array to store the short in. must be offset + 2 in lengthoffset- the offset into bytesOut to store the short
-
bytes2short
public static short bytes2short(byte[] dataIn, int offset) convert bytes into a short- Parameters:
dataIn- the byte array that holds the short. Must be offset +2 in lengthoffset- the offset into dataIn to read the short from- Returns:
- the short
-
int2bytes
public static void int2bytes(int intIn, byte[] bytesOut, int offset) convert an int to bytes- Parameters:
intIn- the int to store as bytesbytesOut- the byte array to store intIn in, must be offset + 4 in lengthoffset- the offset in bytesOut to store intIn at
-
bytes2int
public static int bytes2int(byte[] dataIn, int offset) convert an array of bytes to an int- Parameters:
dataIn- the array of bytes that holds the int, must be offset + 4 in lengthoffset- the offset into dataIn to read the int from- Returns:
- the new int
-
long2bytes
public static void long2bytes(long longIn, byte[] bytesOut, int offset) convert a long to an array of bytes- Parameters:
longIn- the long to convert to bytesbytesOut- the byte array to store longIn into, must be at least offset +8 in lengthoffset- the offset into bytesOut to store the long bytes
-
bytes2long
public static long bytes2long(byte[] dataIn, int offset) Convert an array of bytes to a long- Parameters:
dataIn- the byte array that holds the long bytesoffset- the offset into dataIn to start reading the long bytes- Returns:
- the new long
-
unsignedByte
public static long unsignedByte(byte x) take a byte and return the unsigned version- Parameters:
x- the byte- Returns:
- the unsigned byte
-