Package ghidra.util

# Class Conv

java.lang.Object
ghidra.util.Conv

public class Conv extends Object
Helper methods for converting between number data types without negative promotion.

Consider using java built-in methods for conversion instead of methods from this class.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `BYTE_MASK`
  Deprecated, for removal: This API element is subject to removal in a future version.
  `Byte.toUnsignedInt(byte)` will handle most use cases of this constant
  `static final long`
  `INT_MASK`
  Deprecated, for removal: This API element is subject to removal in a future version.
  `Integer.toUnsignedLong(int)` will handle most use cases of this constant
  `static final int`
  `SHORT_MASK`
  Deprecated, for removal: This API element is subject to removal in a future version.
  `Short.toUnsignedInt(short)` will handle most use cases of this constant

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static int`
  `byteToInt(byte b)`
  Deprecated, for removal: This API element is subject to removal in a future version.
  Use `Byte.toUnsignedInt(byte)` instead
  `static long`
  `byteToLong(byte b)`
  Deprecated, for removal: This API element is subject to removal in a future version.
  Use `Byte.toUnsignedLong(byte)` instead
  `static short`
  `byteToShort(byte b)`
  Deprecated, for removal: This API element is subject to removal in a future version.
  Use other built-ins like `Byte.toUnsignedInt(byte)`
  `static long`
  `intToLong(int i)`
  Deprecated, for removal: This API element is subject to removal in a future version.
  Use `Integer.toUnsignedLong(int)` instead
  `static int`
  `shortToInt(short s)`
  Deprecated, for removal: This API element is subject to removal in a future version.
  Use `Short.toUnsignedInt(short)` instead
  `static long`
  `shortToLong(short s)`
  Deprecated, for removal: This API element is subject to removal in a future version.
  Use `Short.toUnsignedLong(short)` instead
  `static String`
  `toHexString(byte b)`
  Consider using `String.format("%02x", b)` instead.
  `static String`
  `toHexString(int i)`
  Consider using `String.format("%08x", i)` instead.
  `static String`
  `toHexString(long l)`
  Consider using `String.format("%016x", l)` instead.
  `static String`
  `toHexString(short s)`
  Consider using `String.format("%04x", s)` instead.
  `static String`
  `toString(byte[] array)`
  Deprecated, for removal: This API element is subject to removal in a future version.
  Use `new String(bytes, StandardCharSets.US_ASCII)` instead
  `static String`
  `zeropad(String s, int len)`
  Returns a string that is extended to length len with zeroes.

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

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

- ## Field Details

  - ### BYTE_MASK

    @Deprecated(forRemoval=true, since="10.2") public static final int BYTE_MASK
    Deprecated, for removal: This API element is subject to removal in a future version.
    `Byte.toUnsignedInt(byte)` will handle most use cases of this constant
    A byte mask.
    See Also:
      - Constant Field Values

  - ### SHORT_MASK

    @Deprecated(forRemoval=true, since="10.2") public static final int SHORT_MASK
    Deprecated, for removal: This API element is subject to removal in a future version.
    `Short.toUnsignedInt(short)` will handle most use cases of this constant
    A short mask.
    See Also:
      - Constant Field Values

  - ### INT_MASK

    @Deprecated(forRemoval=true, since="10.2") public static final long INT_MASK
    Deprecated, for removal: This API element is subject to removal in a future version.
    `Integer.toUnsignedLong(int)` will handle most use cases of this constant
    An integer mask.
    See Also:
      - Constant Field Values

- ## Method Details

  - ### byteToShort

    @Deprecated(forRemoval=true, since="10.2") public static short byteToShort(byte b)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Use other built-ins like `Byte.toUnsignedInt(byte)`
    Parameters:
      `b` - the byte
    Returns:
      the short equivalent of the byte

  - ### byteToInt

    @Deprecated(forRemoval=true, since="10.2") public static int byteToInt(byte b)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Use `Byte.toUnsignedInt(byte)` instead
    Converts a byte to an integer.
    Parameters:
      `b` - the byte
    Returns:
      the integer equivalent of the byte

  - ### byteToLong

    @Deprecated(forRemoval=true, since="10.2") public static long byteToLong(byte b)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Use `Byte.toUnsignedLong(byte)` instead
    Converts a byte to a long.
    Parameters:
      `b` - the byte
    Returns:
      the long equivalent of the byte

  - ### shortToInt

    @Deprecated(forRemoval=true, since="10.2") public static int shortToInt(short s)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Use `Short.toUnsignedInt(short)` instead
    Converts a short to an integer.
    Parameters:
      `s` - the short
    Returns:
      the integer equivalent of the short

  - ### shortToLong

    @Deprecated(forRemoval=true, since="10.2") public static long shortToLong(short s)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Use `Short.toUnsignedLong(short)` instead
    Converts a short to a long.
    Parameters:
      `s` - the short
    Returns:
      the long eqivalent of the short

  - ### intToLong

    @Deprecated(forRemoval=true, since="10.2") public static long intToLong(int i)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Use `Integer.toUnsignedLong(int)` instead
    Converts an integer to a long.
    Parameters:
      `i` - the integer
    Returns:
      the long equivalent of the long

  - ### toString

    @Deprecated(forRemoval=true, since="10.2") public static String toString(byte[] array)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Use `new String(bytes, StandardCharSets.US_ASCII)` instead

    Old and incorrect way to convert bytes to a String by casting their values to chars. Do not use. Does not seem to be used in current codebase.

    Parameters:
      `array` -
    Returns:

  - ### toHexString

    public static String toHexString(byte b)
    Consider using `String.format("%02x", b)` instead.

    Converts a byte into a padded hex string.

    Parameters:
      `b` - the byte
    Returns:
      the padded hex string

  - ### toHexString

    public static String toHexString(short s)
    Consider using `String.format("%04x", s)` instead.

    Converts a short into a padded hex string.

    Parameters:
      `s` - the short
    Returns:
      the padded hex string

  - ### toHexString

    public static String toHexString(int i)
    Consider using `String.format("%08x", i)` instead.

    Converts an integer into a padded hex string.

    Parameters:
      `i` - the integer
    Returns:
      the padded hex string

  - ### toHexString

    public static String toHexString(long l)
    Consider using `String.format("%016x", l)` instead.

    Converts a long into a padded hex string.

    Parameters:
      `l` - the long
    Returns:
      the padded hex string

  - ### zeropad

    public static String zeropad(String s, int len)
    Returns a string that is extended to length len with zeroes.
    Parameters:
      `s` - The string to pad
      `len` - The length of the return string
    Returns:
      A string that has been left-padded with zeros to be of length len