Package ghidra.util

# Class LittleEndianDataConverter

java.lang.Object
ghidra.util.LittleEndianDataConverter

All Implemented Interfaces:
  `DataConverter`, `Serializable`

Direct Known Subclasses:
  `GhidraLittleEndianDataConverter`

public class LittleEndianDataConverter extends Object implements DataConverter
Helper class to convert a byte array to a Java primitive in Little endian order, and to convert a primitive to a byte array.

See Also:
  - Serialized Form

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final LittleEndianDataConverter`
  `INSTANCE`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `LittleEndianDataConverter()`
  Don't use this constructor to create new instances of this class.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `BigInteger`
  `getBigInteger(byte[] b, int offset, int size, boolean signed)`
  Get the value from the given byte array using the specified size.
  `int`
  `getInt(byte[] b, int offset)`
  Get the int value from the given byte array.
  `long`
  `getLong(byte[] b, int offset)`
  Get the long value from the given byte array.
  `short`
  `getShort(byte[] b, int offset)`
  Get the short value from the given byte array.
  `long`
  `getValue(byte[] b, int offset, int size)`
  Get the unsigned value from the given byte array using the specified integer size, returned as a long.
  `void`
  `putBigInteger(byte[] b, int offset, int size, BigInteger value)`
  Writes a value of specified size into the byte array at the given offset
  `void`
  `putInt(byte[] b, int offset, int value)`
  Writes a int value into the byte array at the given offset.
  `void`
  `putShort(byte[] b, int offset, short value)`
  Writes a short value into the byte array at the given offset
  `void`
  `putValue(long value, int size, byte[] b, int offset)`
  Converts the given value to bytes using the number of least significant bytes specified by size.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface ghidra.util.DataConverter

  `getBigInteger, getBytes, getBytes, getBytes, getBytes, getBytes, getBytes, getBytes, getBytes, getBytes, getBytes, getBytes, getBytes, getInt, getLong, getShort, getSignedValue, getSignedValue, getValue, isBigEndian, putBigInteger, putInt, putLong, putLong, putShort`

- ## Field Details

  - ### INSTANCE

    public static final LittleEndianDataConverter INSTANCE

- ## Constructor Details

  - ### LittleEndianDataConverter

    public LittleEndianDataConverter()
    Don't use this constructor to create new instances of this class. Use the static `INSTANCE` instead or `DataConverter.getInstance(boolean)`

- ## Method Details

  - ### getShort

    public short getShort(byte[] b, int offset)
    Description copied from interface: `DataConverter`
    Get the short value from the given byte array.
    Specified by:
      `getShort` in interface `DataConverter`
    Parameters:
      `b` - array containing bytes
      `offset` - offset into byte array for getting the short
    Returns:
      signed short value

  - ### getInt

    public int getInt(byte[] b, int offset)
    Description copied from interface: `DataConverter`
    Get the int value from the given byte array.
    Specified by:
      `getInt` in interface `DataConverter`
    Parameters:
      `b` - array containing bytes
      `offset` - offset into byte array for getting the int
    Returns:
      signed int value

  - ### getLong

    public long getLong(byte[] b, int offset)
    Description copied from interface: `DataConverter`
    Get the long value from the given byte array.
    Specified by:
      `getLong` in interface `DataConverter`
    Parameters:
      `b` - array containing bytes
      `offset` - offset into byte array for getting the long
    Returns:
      signed long value

  - ### getValue

    public long getValue(byte[] b, int offset, int size)
    Description copied from interface: `DataConverter`
    Get the unsigned value from the given byte array using the specified integer size, returned as a long.

    Values with a size less than sizeof(long) will not have their sign bit extended and therefore will appear as an 'unsigned' value.

    Casting the 'unsigned' long value to the correctly sized smaller java primitive will cause the value to appear as a signed value.

    Values of size 8 (ie. longs) will be signed.

    Specified by:
      `getValue` in interface `DataConverter`
    Parameters:
      `b` - array containing bytes
      `offset` - offset into byte array for getting the long
      `size` - number of bytes (1 - 8) to use from array
    Returns:
      unsigned value

  - ### getBigInteger

    public BigInteger getBigInteger(byte[] b, int offset, int size, boolean signed)
    Description copied from interface: `DataConverter`
    Get the value from the given byte array using the specified size.
    Specified by:
      `getBigInteger` in interface `DataConverter`
    Parameters:
      `b` - array containing bytes
      `offset` - offset into byte array for getting the long
      `size` - number of bytes to use from array
      `signed` - boolean flag indicating the value is signed
    Returns:
      `BigInteger` with value

  - ### putShort

    public void putShort(byte[] b, int offset, short value)
    Description copied from interface: `DataConverter`
    Writes a short value into the byte array at the given offset
    Specified by:
      `putShort` in interface `DataConverter`
    Parameters:
      `b` - array to contain the bytes
      `offset` - the offset into the byte array to store the value
      `value` - the short value

  - ### putInt

    public void putInt(byte[] b, int offset, int value)
    Description copied from interface: `DataConverter`
    Writes a int value into the byte array at the given offset.

    See `DataConverter.getBytes(int, byte[], int)`

    Specified by:
      `putInt` in interface `DataConverter`
    Parameters:
      `b` - array to contain the bytes
      `offset` - the offset into the byte array to store the value
      `value` - the int value

  - ### putValue

    public void putValue(long value, int size, byte[] b, int offset)
    Description copied from interface: `DataConverter`
    Converts the given value to bytes using the number of least significant bytes specified by size.

    Specified by:
      `putValue` in interface `DataConverter`
    Parameters:
      `value` - value to convert to bytes
      `size` - number of least significant bytes of value to be written to the byte array
      `b` - byte array to store bytes
      `offset` - offset into byte array to put the bytes

  - ### putBigInteger

    public void putBigInteger(byte[] b, int offset, int size, BigInteger value)
    Description copied from interface: `DataConverter`
    Writes a value of specified size into the byte array at the given offset

    See `DataConverter.getBytes(BigInteger, int, byte[], int)`

    Specified by:
      `putBigInteger` in interface `DataConverter`
    Parameters:
      `b` - array to contain the bytes
      `offset` - the offset into the byte array to store the value
      `size` - number of bytes to be written
      `value` - BigInteger value to convert