Class IntegerFormatting



  • public class IntegerFormatting
    extends Object
    A utility class for converting primitive int and long values to hex, octal and binary strings. Derived from Integer.java and Long.java from the OpenJDK project.
    • Constructor Detail

      • IntegerFormatting

        public IntegerFormatting()
    • Method Detail

      • intToHexString

        public static String intToHexString(int i,
                                            Case c)
        Returns a string representation of the integer argument as an unsigned integer in base 16.

        The unsigned integer value is the argument plus 232 if the argument is negative; otherwise, it is equal to the argument. This value is converted to a string of ASCII digits in hexadecimal (base 16) with no extra leading 0s. If the unsigned magnitude is zero, it is represented by a single zero character '0' ('\u0030'); otherwise, the first character of the representation of the unsigned magnitude will not be the zero character. The following characters are used as hexadecimal digits:

        0123456789abcdef
        These are the characters '\u0030' through '\u0039' and '\u0061' through '\u0066'. If uppercase letters are desired, the String.toUpperCase() method may be called on the result:
        Integer.toHexString(n).toUpperCase()
        Parameters:
        i - an integer to be converted to a string.
        Returns:
        the string representation of the unsigned integer value represented by the argument in hexadecimal (base 16).
        Since:
        JDK1.0.2
      • intToOctalString

        public static String intToOctalString(int i)
        Returns a string representation of the integer argument as an unsigned integer in base 8.

        The unsigned integer value is the argument plus 232 if the argument is negative; otherwise, it is equal to the argument. This value is converted to a string of ASCII digits in octal (base 8) with no extra leading 0s.

        If the unsigned magnitude is zero, it is represented by a single zero character '0' ('\u0030'); otherwise, the first character of the representation of the unsigned magnitude will not be the zero character. The following characters are used as octal digits:

        01234567
        These are the characters '\u0030' through '\u0037'.
        Parameters:
        i - an integer to be converted to a string.
        Returns:
        the string representation of the unsigned integer value represented by the argument in octal (base 8).
        Since:
        JDK1.0.2
      • intToBinaryString

        public static String intToBinaryString(int i)
        Returns a string representation of the integer argument as an unsigned integer in base 2.

        The unsigned integer value is the argument plus 232 if the argument is negative; otherwise it is equal to the argument. This value is converted to a string of ASCII digits in binary (base 2) with no extra leading 0s. If the unsigned magnitude is zero, it is represented by a single zero character '0' ('\u0030'); otherwise, the first character of the representation of the unsigned magnitude will not be the zero character. The characters '0' ('\u0030') and '1' ('\u0031') are used as binary digits.

        Parameters:
        i - an integer to be converted to a string.
        Returns:
        the string representation of the unsigned integer value represented by the argument in binary (base 2).
        Since:
        JDK1.0.2
      • longToHexString

        public static String longToHexString(long i,
                                             Case c)
        Returns a string representation of the long argument as an unsigned integer in base 16.

        The unsigned long value is the argument plus 264 if the argument is negative; otherwise, it is equal to the argument. This value is converted to a string of ASCII digits in hexadecimal (base 16) with no extra leading 0s.

        The value of the argument can be recovered from the returned string s by calling Long.parseUnsignedLong(s, 16).

        If the unsigned magnitude is zero, it is represented by a single zero character '0' ('\u0030'); otherwise, the first character of the representation of the unsigned magnitude will not be the zero character. The following characters are used as hexadecimal digits:

        0123456789abcdef
        These are the characters '\u0030' through '\u0039' and '\u0061' through '\u0066'. If uppercase letters are desired, the String.toUpperCase() method may be called on the result:
        Long.toHexString(n).toUpperCase()
        Parameters:
        i - a long to be converted to a string.
        Returns:
        the string representation of the unsigned long value represented by the argument in hexadecimal (base 16).
        Since:
        JDK 1.0.2
        See Also:
        #parseUnsignedLong(String, int), #longToUnsignedString(long, int)
      • longToOctalString

        public static String longToOctalString(long i)
        Returns a string representation of the long argument as an unsigned integer in base 8.

        The unsigned long value is the argument plus 264 if the argument is negative; otherwise, it is equal to the argument. This value is converted to a string of ASCII digits in octal (base 8) with no extra leading 0s.

        The value of the argument can be recovered from the returned string s by calling Long.parseUnsignedLong(s, 8).

        If the unsigned magnitude is zero, it is represented by a single zero character '0' ('\u0030'); otherwise, the first character of the representation of the unsigned magnitude will not be the zero character. The following characters are used as octal digits:

        01234567
        These are the characters '\u0030' through '\u0037'.
        Parameters:
        i - a long to be converted to a string.
        Returns:
        the string representation of the unsigned long value represented by the argument in octal (base 8).
        Since:
        JDK 1.0.2
        See Also:
        #parseUnsignedLong(String, int), #longToUnsignedString(long, int)
      • longToBinaryString

        public static String longToBinaryString(long i)
        Returns a string representation of the long argument as an unsigned integer in base 2.

        The unsigned long value is the argument plus 264 if the argument is negative; otherwise, it is equal to the argument. This value is converted to a string of ASCII digits in binary (base 2) with no extra leading 0s.

        The value of the argument can be recovered from the returned string s by calling Long.parseUnsignedLong(s, 2).

        If the unsigned magnitude is zero, it is represented by a single zero character '0' ('\u0030'); otherwise, the first character of the representation of the unsigned magnitude will not be the zero character. The characters '0' ('\u0030') and '1' ('\u0031') are used as binary digits.

        Parameters:
        i - a long to be converted to a string.
        Returns:
        the string representation of the unsigned long value represented by the argument in binary (base 2).
        Since:
        JDK 1.0.2
        See Also:
        #parseUnsignedLong(String, int), #longToUnsignedString(long, int)