# Class HexUtils

java.lang.Object
org.apache.tomcat.util.buf.HexUtils

public final class HexUtils extends Object
Tables useful when converting byte arrays to and from strings of hexadecimal digits. Code from Ajp11, from Apache's JServ.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static byte[]`
  `fromHexString(String input)`
  Convert a hexadecimal string to a byte array.
  `static int`
  `getDec(int index)`
  Get the decimal value of the character at the given index.
  `static byte`
  `getHex(int index)`
  Get the hexadecimal byte for the given index.
  `static String`
  `toHexString(byte[] bytes)`
  Convert a byte array to a hexadecimal string representation.
  `static String`
  `toHexString(char c)`
  Convert a character to a hexadecimal string representation.

  ### Methods inherited from class Object

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

- ## Method Details

  - ### getDec

    public static int getDec(int index)
    Get the decimal value of the character at the given index.
    Parameters:
      `index` - the character index
    Returns:
      the decimal value, or -1 if the character is not a valid hex digit

  - ### getHex

    public static byte getHex(int index)
    Get the hexadecimal byte for the given index.
    Parameters:
      `index` - the index into the hex table
    Returns:
      the hexadecimal byte

  - ### toHexString

    public static String toHexString(char c)
    Convert a character to a hexadecimal string representation.
    Parameters:
      `c` - the character to convert
    Returns:
      the hexadecimal string representation of the character

  - ### toHexString

    public static String toHexString(byte[] bytes)
    Convert a byte array to a hexadecimal string representation.
    Parameters:
      `bytes` - the byte array to convert
    Returns:
      the hexadecimal string, or `null` if the input is `null`

  - ### fromHexString

    public static byte[] fromHexString(String input)
    Convert a hexadecimal string to a byte array.
    Parameters:
      `input` - the hexadecimal string to convert
    Returns:
      the byte array, or `null` if the input is `null`
    Throws:
      `IllegalArgumentException` - if the input has an odd number of characters or contains non-hexadecimal characters