Package org.jf.util

Class Hex


  • public final class Hex
    extends java.lang.Object
    Utilities for formatting numbers as hexadecimal.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String dump​(byte[] arr, int offset, int length, int outOffset, int bpl, int addressLength)
      Formats a hex dump of a portion of a byte[].
      static java.lang.String s1​(int v)
      Formats an int as a 1-byte signed hex value.
      static java.lang.String s2​(int v)
      Formats an int as a 2-byte signed hex value.
      static java.lang.String s4​(int v)
      Formats an int as a 4-byte signed hex value.
      static java.lang.String s8​(long v)
      Formats a long as an 8-byte signed hex value.
      static java.lang.String u1​(int v)
      Formats an int as a 1-byte unsigned hex value.
      static java.lang.String u2​(int v)
      Formats an int as a 2-byte unsigned hex value.
      static java.lang.String u2or4​(int v)
      Formats an int as either a 2-byte unsigned hex value (if the value is small enough) or a 4-byte unsigned hex value (if not).
      static java.lang.String u3​(int v)
      Formats an int as a 3-byte unsigned hex value.
      static java.lang.String u4​(int v)
      Formats an int as a 4-byte unsigned hex value.
      static java.lang.String u8​(long v)
      Formats a long as an 8-byte unsigned hex value.
      static java.lang.String uNibble​(int v)
      Formats an int as a 4-bit unsigned hex nibble.
      • Methods inherited from class java.lang.Object

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

      • u8

        public static java.lang.String u8​(long v)
        Formats a long as an 8-byte unsigned hex value.
        Parameters:
        v - value to format
        Returns:
        non-null; formatted form
      • u4

        public static java.lang.String u4​(int v)
        Formats an int as a 4-byte unsigned hex value.
        Parameters:
        v - value to format
        Returns:
        non-null; formatted form
      • u3

        public static java.lang.String u3​(int v)
        Formats an int as a 3-byte unsigned hex value.
        Parameters:
        v - value to format
        Returns:
        non-null; formatted form
      • u2

        public static java.lang.String u2​(int v)
        Formats an int as a 2-byte unsigned hex value.
        Parameters:
        v - value to format
        Returns:
        non-null; formatted form
      • u2or4

        public static java.lang.String u2or4​(int v)
        Formats an int as either a 2-byte unsigned hex value (if the value is small enough) or a 4-byte unsigned hex value (if not).
        Parameters:
        v - value to format
        Returns:
        non-null; formatted form
      • u1

        public static java.lang.String u1​(int v)
        Formats an int as a 1-byte unsigned hex value.
        Parameters:
        v - value to format
        Returns:
        non-null; formatted form
      • uNibble

        public static java.lang.String uNibble​(int v)
        Formats an int as a 4-bit unsigned hex nibble.
        Parameters:
        v - value to format
        Returns:
        non-null; formatted form
      • s8

        public static java.lang.String s8​(long v)
        Formats a long as an 8-byte signed hex value.
        Parameters:
        v - value to format
        Returns:
        non-null; formatted form
      • s4

        public static java.lang.String s4​(int v)
        Formats an int as a 4-byte signed hex value.
        Parameters:
        v - value to format
        Returns:
        non-null; formatted form
      • s2

        public static java.lang.String s2​(int v)
        Formats an int as a 2-byte signed hex value.
        Parameters:
        v - value to format
        Returns:
        non-null; formatted form
      • s1

        public static java.lang.String s1​(int v)
        Formats an int as a 1-byte signed hex value.
        Parameters:
        v - value to format
        Returns:
        non-null; formatted form
      • dump

        public static java.lang.String dump​(byte[] arr,
                                            int offset,
                                            int length,
                                            int outOffset,
                                            int bpl,
                                            int addressLength)
        Formats a hex dump of a portion of a byte[]. The result is always newline-terminated, unless the passed-in length was zero, in which case the result is always the empty string ("").
        Parameters:
        arr - non-null; array to format
        offset - >= 0; offset to the part to dump
        length - >= 0; number of bytes to dump
        outOffset - >= 0; first output offset to print
        bpl - >= 0; number of bytes of output per line
        addressLength - {2,4,6,8}; number of characters for each address header
        Returns:
        non-null; a string of the dump