Package rma.util

Class ByteConversion

java.lang.Object
rma.util.ByteConversion

public class ByteConversion extends Object
Class to convert between bytes and other primatives
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Color
    bytes2color(byte[] dataIn, int offset)
    convert an array of bytes into a Color
    static int
    bytes2int(byte[] dataIn, int offset)
    convert an array of bytes to an int
    static long
    bytes2long(byte[] dataIn, int offset)
    Convert an array of bytes to a long
    static short
    bytes2short(byte[] dataIn, int offset)
    convert bytes into a short
    static void
    color2bytes(Color color, byte[] dataOut, int offset)
    convert a Color to a array of bytes
    static void
    int2bytes(int intIn, byte[] bytesOut, int offset)
    convert an int to bytes
    static void
    long2bytes(long longIn, byte[] bytesOut, int offset)
    convert a long to an array of bytes
    static void
    short2bytes(short shortIn, byte[] bytesOut, int offset)
    convert a short to an array of bytes
    static long
    unsignedByte(byte x)
    take a byte and return the unsigned version

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ByteConversion

      public ByteConversion()
  • Method Details

    • color2bytes

      public static void color2bytes(Color color, byte[] dataOut, int offset)
      convert a Color to a array of bytes
      Parameters:
      color - the color
      dataOut - the byte array to store into. Needs to be at least offset + 3 in length
      offset - the offset into dataOut to store the color byte info
    • bytes2color

      public static Color bytes2color(byte[] dataIn, int offset)
      convert an array of bytes into a Color
      Parameters:
      dataIn - the byte array that hold the Color info. must be at least offset + 3 in length
      offset - the offset into dataIn where the Color info 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 bytes
      bytesOut - the array to store the short in. must be offset + 2 in length
      offset - 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 length
      offset - 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 bytes
      bytesOut - the byte array to store intIn in, must be offset + 4 in length
      offset - 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 length
      offset - 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 bytes
      bytesOut - the byte array to store longIn into, must be at least offset +8 in length
      offset - 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 bytes
      offset - 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