Class BinaryPDS4ConversionUtils

java.lang.Object
gov.nasa.pds.web.ui.utils.BinaryPDS4ConversionUtils

public class BinaryPDS4ConversionUtils
extends Object
Helper class to convert between PDS4 data types
Author:
ghflore1
  • Constructor Details

    • BinaryPDS4ConversionUtils

      public BinaryPDS4ConversionUtils()
  • Method Details

    • convertSignedLSBIntegers

      public static long convertSignedLSBIntegers​(byte[] b, int n)
      Converts an array of bytes into an int. The array of bytes may be of length 1, 2, 3, or 4, in little-endian order. That is, b[n-1] holds the most significant bits, b[n-1] the least. The bytes are assumed to be signed.
      Parameters:
      b - the array of bytes, in little-endian order
      n - the number of bytes to convert in the array, from 1 to the size of an int
      Returns:
      the signed int value represented by the bytes
    • convertUnsignedLSBIntegers

      public static long convertUnsignedLSBIntegers​(byte[] b, int n)
      Converts an array of bytes into a long, permitting unsigned bytes. The array of bytes may be of length 1, 2, 3, or 4, in big-endian order. That is, b[0] holds the most significant bits, b[n-1] the least.
      Parameters:
      b - the array of bytes, in big-endian order
      n - the number of bytes to convert in the array, from 1 to the size of an int
      Returns:
      the signed int value represented by the bytes
    • convertSignedMSBIntegers

      public static long convertSignedMSBIntegers​(byte[] b, int n)
      Converts an array of bytes into an int. The array of bytes may be of length 1, 2, 3, or 4, in big-endian order. That is, b[0] holds the most significant bits, b[n-1] the least. The bytes are assumed to be signed.
      Parameters:
      b - the array of bytes, in big-endian order
      n - the number of bytes to convert in the array, from 1 to the size of an int
      Returns:
      the signed int value represented by the bytes
    • convertUnsignedMSBIntegers

      public static long convertUnsignedMSBIntegers​(byte[] b, int n)
      Converts an array of bytes into a long, permitting unsigned bytes. The array of bytes may be of length 2, 4, or 8, in big-endian order. That is, b[0] holds the most significant bits, b[n-1] the least.
      Parameters:
      b - the array of bytes, in big-endian order
      n - the number of bytes to convert in the array, from 1 to the size of an int
      Returns:
      the signed int value represented by the bytes
    • convertByte

      public static long convertByte​(byte[] b, int n)
      Converts an array of bytes into a long, permitting unsigned bytes. The array of bytes is of size 1 byte
      Parameters:
      b - the array of bytes, in big-endian order
      n - the number of bytes to convert in the array, from 1 to the size of an int
      Returns:
      the signed int value represented by the bytes
    • convertByteArrayToLong

      public static long convertByteArrayToLong​(byte[] b)
      Convert a byte array of size 8 bytes to type long
      Parameters:
      b - : byte array of size 8 bytes
      Returns:
      long representation of the byte array Note: Need to type cast to type long since cannot shift pass 31 bits
    • convertByteArrayToInt

      public static int convertByteArrayToInt​(byte[] b)
      Convert a byte array of size 4 bytes to type int
      Parameters:
      b - : byte array if size 4 bytes
      Returns:
      int representation of the byte array
    • convertByteArrayToShort

      public static short convertByteArrayToShort​(byte[] b)
      Convert a byte array of size 2 bytes to type short
      Parameters:
      b - : byte array if size 2 bytes
      Returns:
      shot representation of the byte array
    • IEEE754LSBToIEEE754MSBSingle

      public static int IEEE754LSBToIEEE754MSBSingle​(byte[] b)
      Convert from IEEE754LSBSingle type to IEEE754MSBSingle precision
      Parameters:
      b - - byte array of size 4 bytes
      Returns:
      The byte array in integer format
    • IEEE754LSBToIEEE754MSBDouble

      public static long IEEE754LSBToIEEE754MSBDouble​(byte[] b)
      Convert from IEEE754LSBDouble type to IEEE754MSBDouble precision
      Parameters:
      b - - byte array of size 8 bytes
      Returns:
      Byte array in long type