Class Hex


  • public final class Hex
    extends Object
    Utility for hexidecimal encoding and decoding.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static byte[] DECODE
      Decode table which stores characters from 0 to f.
      private static char[] HEX_CHARS
      Hexidecimal characters.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Hex()
      Default constructor.
    • Field Detail

      • HEX_CHARS

        private static final char[] HEX_CHARS
        Hexidecimal characters.
      • DECODE

        private static final byte[] DECODE
        Decode table which stores characters from 0 to f. Anything higher than 'f' is invalid so that is the max size of the array.
    • Constructor Detail

      • Hex

        private Hex()
        Default constructor.
    • Method Detail

      • encode

        public static char[] encode​(byte... value)
        This will convert the supplied value to a hex encoded string. Returns null if the supplied value is null.
        Parameters:
        value - to hex encode
        Returns:
        hex encoded value
      • decode

        public static byte[] decode​(char... value)
        This will convert the supplied value from a hex encoded string. Returns null if the supplied value is null.
        Parameters:
        value - to hex decode
        Returns:
        hex decoded value
        Throws:
        IllegalArgumentException - if value is not valid hexidecimal
      • decode

        private static int decode​(char[] hex,
                                  int i)
        Decodes the supplied character to its corresponding nibble.
        Parameters:
        hex - to read character from
        i - index of hex to read
        Returns:
        0-15 integer
        Throws:
        IllegalArgumentException - if the character is not valid hex