Class HexString


  • public class HexString
    extends java.lang.Object
    Utility class to handle all sorts of hexadecimal string conversions
    Author:
    Andreas Schwier (info@cardcontact.de)
    • Constructor Summary

      Constructors 
      Constructor Description
      HexString()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String dump​(byte[] data)
      Dump buffer in hexadecimal format with offset and character codes
      static java.lang.String dump​(byte[] data, int offset, int length)
      Dump buffer in hexadecimal format with offset and character codes.
      static java.lang.String dump​(byte[] data, int offset, int length, int widths)
      Dump buffer in hexadecimal format with offset and character codes
      static java.lang.String dump​(byte[] data, int offset, int length, int widths, int indent)
      Dump buffer in hexadecimal format with offset and character codes
      static java.lang.String hexifyByte​(byte val)
      Convert byte value to hexadecimal byte presentation
      static java.lang.String hexifyByte​(int val)
      Convert integer value to hexadecimal byte presentation
      static java.lang.String hexifyByteArray​(byte[] buffer)
      Convert byte array to hexadecimal string
      static java.lang.String hexifyByteArray​(byte[] buffer, char delimiter)
      Convert byte array to hexadecimal string
      static java.lang.String hexifyByteArray​(byte[] buffer, char delimiter, int length)
      Convert byte array to hexadecimal string
      static java.lang.String hexifyInt​(int val)
      Convert int value to hexadecimal int presentation
      static java.lang.String hexifyShort​(int val)
      Convert int value to hexadecimal short presentation
      static byte[] parseHexString​(java.lang.String str)
      Parse string of hexadecimal characters into byte array
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • HexString

        public HexString()
    • Method Detail

      • hexifyByte

        public static java.lang.String hexifyByte​(int val)
        Convert integer value to hexadecimal byte presentation
        Parameters:
        val - Value
        Returns:
        2 digit hexadecimal string
      • hexifyByte

        public static java.lang.String hexifyByte​(byte val)
        Convert byte value to hexadecimal byte presentation
        Parameters:
        val - Value
        Returns:
        2 digit hexadecimal string
      • hexifyShort

        public static java.lang.String hexifyShort​(int val)
        Convert int value to hexadecimal short presentation
        Parameters:
        val - Value
        Returns:
        4 digit hexadecimal string
      • hexifyInt

        public static java.lang.String hexifyInt​(int val)
        Convert int value to hexadecimal int presentation
        Parameters:
        val - Value
        Returns:
        8 digit hexadecimal string
      • hexifyByteArray

        public static java.lang.String hexifyByteArray​(byte[] buffer,
                                                       char delimiter,
                                                       int length)
        Convert byte array to hexadecimal string
        Parameters:
        buffer - Buffer with bytes
        delimiter - Delimiter to be inserted between bytes. Use 0 for none.
        length - Number of byte to convert
        Returns:
        String with hexadecimal data
      • hexifyByteArray

        public static java.lang.String hexifyByteArray​(byte[] buffer,
                                                       char delimiter)
        Convert byte array to hexadecimal string
        Parameters:
        buffer - Buffer with bytes
        delimiter - Delimiter to be inserted between bytes. Use 0 for none.
        Returns:
        String with hexadecimal data
      • hexifyByteArray

        public static java.lang.String hexifyByteArray​(byte[] buffer)
        Convert byte array to hexadecimal string
        Parameters:
        buffer - Buffer with bytes
        Returns:
        String with hexadecimal data
      • dump

        public static java.lang.String dump​(byte[] data,
                                            int offset,
                                            int length,
                                            int widths,
                                            int indent)
        Dump buffer in hexadecimal format with offset and character codes
        Parameters:
        data - Byte buffer
        offset - Offset into byte buffer
        length - Length of data to be dumped
        widths - Number of bytes per line
        indent - Number of blanks to indent each line
        Returns:
        String containing the dump
      • dump

        public static java.lang.String dump​(byte[] data,
                                            int offset,
                                            int length,
                                            int widths)
        Dump buffer in hexadecimal format with offset and character codes
        Parameters:
        data - Byte buffer
        offset - Offset into byte buffer
        length - Length of data to be dumped
        widths - Number of bytes per line
        Returns:
        String containing the dump
      • dump

        public static java.lang.String dump​(byte[] data,
                                            int offset,
                                            int length)
        Dump buffer in hexadecimal format with offset and character codes. Output 16 bytes per line
        Parameters:
        data - Byte buffer
        offset - Offset into byte buffer
        length - Length of data to be dumped
        Returns:
        String containing the dump
      • dump

        public static java.lang.String dump​(byte[] data)
        Dump buffer in hexadecimal format with offset and character codes
        Parameters:
        data - Byte buffer
        Returns:
        String containing the dump
      • parseHexString

        public static byte[] parseHexString​(java.lang.String str)
        Parse string of hexadecimal characters into byte array
        Parameters:
        str - String to parse
        Returns:
        byte array containing the string