Class NumeralSystemHelper

java.lang.Object
com.shaiksphere.mindsmine.jems.NumeralSystemHelper

public final class NumeralSystemHelper
extends Object
A collection of useful static methods to deal with numeral system. A numeral system is a writing system for expressing numbers; that is, a mathematical notation for representing numbers of a given set, using digits or other symbols in a consistent manner.
Since:
3.1.0
Author:
Mohammed Shaik Hussain Ali
See Also:
Numeral System (Wikipedia)
  • Method Details

    • convert

      public static String convert​(String valueStr, int from, int to)
      Returns a string representation of the first argument in the radix specified by the third argument from the radix specified by the second argument.

      If the radix is smaller than Character.MIN_RADIX or larger than Character.MAX_RADIX, then the radix 10 is used instead.

      If the first argument is negative, the first element of the result is the ASCII minus character '-'. If the first argument is not negative, no sign character appears in the result.

      The remaining characters of the result represent the magnitude of the first argument. If the magnitude is zero, it is represented by a single zero character '0'; otherwise, the first character of the representation of the magnitude will not be the zero character. The following ASCII characters are used as digits: 0123456789abcdefghijklmnopqrstuvwxyz

      These are '0' through '9' and 'a' through 'z'. If radix is N, then the first N of these characters are used as radix-N digits in the order shown. Thus, the digits for hexadecimal (radix 16) are 0123456789abcdef. If uppercase letters are desired, the String.toUpperCase() method may be called on the result.
      Parameters:
      valueStr - a string to be converted to the desired system.
      from - the radix to which the string representation is in.
      to - the radix to use in the string representation.
      Returns:
      a string representation of the argument in the specified radix.
      Since:
      3.1.0
    • convert

      public static String convert​(int value, int to)
      Returns a string representation of the first argument in the radix specified by the third argument from the radix specified by the second argument.

      Convenience method equivalent to convert(Integer.toString(value), 10, to)
      Parameters:
      value - an integer to be converted to the desired system.
      to - the radix to use in the string representation.
      Returns:
      a string representation of the argument in the specified radix.
      Since:
      3.1.0
      See Also:
      convert(String, int, int)
    • convertDecimalToHexadecimal

      public static String convertDecimalToHexadecimal​(int integer)
      Returns a string representation of the integer argument as an unsigned integer in base 16.
      Parameters:
      integer - 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:
      3.1.0
    • convertDecimalToBinary

      public static String convertDecimalToBinary​(int integer)
      Returns a string representation of the integer argument as an unsigned integer in base 2.
      Parameters:
      integer - 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:
      3.1.0
    • convertDecimalToOctal

      public static String convertDecimalToOctal​(int integer)
      Returns a string representation of the integer argument as an unsigned integer in base 8.
      Parameters:
      integer - 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:
      3.1.0
    • convertBinaryToHexadecimal

      public static String convertBinaryToHexadecimal​(String binaryStr)
      Returns a string representation of the binary value as an unsigned integer in base 16.
      Parameters:
      binaryStr - a binary value to be converted to a hexadecimal string.
      Returns:
      the string representation of the binary value in hexadecimal (base 16).
      Since:
      3.1.0
    • convertBinaryToOctal

      public static String convertBinaryToOctal​(String binaryStr)
      Returns a string representation of the binary value as an unsigned integer in base 8.
      Parameters:
      binaryStr - a binary value to be converted to an octal string.
      Returns:
      the string representation of the binary value in octal (base 8).
      Since:
      3.1.0
    • convertBinaryToDecimal

      public static String convertBinaryToDecimal​(String binaryStr)
      Returns a string representation of the binary value as an unsigned integer in base 10.
      Parameters:
      binaryStr - a binary value to be converted to a decimal string.
      Returns:
      the string representation of the binary value in decimal (base 10).
      Since:
      3.1.0
    • convertHexadecimalToBinary

      public static String convertHexadecimalToBinary​(String hexStr)
      Returns a string representation of the hexadecimal value as an unsigned integer in base 2.
      Parameters:
      hexStr - a hexadecimal value to be converted to a binary string.
      Returns:
      the string representation of the hexadecimal value in binary (base 2).
      Since:
      3.1.0
    • convertHexadecimalToOctal

      public static String convertHexadecimalToOctal​(String hexStr)
      Returns a string representation of the hexadecimal value as an unsigned integer in base 8.
      Parameters:
      hexStr - a hexadecimal value to be converted to an octal string.
      Returns:
      the string representation of the hexadecimal value in octal (base 8).
      Since:
      3.1.0
    • convertHexadecimalToDecimal

      public static String convertHexadecimalToDecimal​(String hexStr)
      Returns a string representation of the hexadecimal value as an unsigned integer in base 10.
      Parameters:
      hexStr - a hexadecimal value to be converted to a decimal string.
      Returns:
      the string representation of the hexadecimal value in decimal (base 10).
      Since:
      3.1.0
    • convertOctalToBinary

      public static String convertOctalToBinary​(String octalStr)
      Returns a string representation of the octal value as an unsigned integer in base 2.
      Parameters:
      octalStr - an octal value to be converted to a binary string.
      Returns:
      the string representation of the octal value in binary (base 2).
      Since:
      3.1.0
    • convertOctalToHexadecimal

      public static String convertOctalToHexadecimal​(String octalStr)
      Returns a string representation of the octal value as an unsigned integer in base 16.
      Parameters:
      octalStr - an octal value to be converted to a hexadecimal string.
      Returns:
      the string representation of the octal value in hexadecimal (base 16).
      Since:
      3.1.0
    • convertOctalToDecimal

      public static String convertOctalToDecimal​(String octalStr)
      Returns a string representation of the octal value as an unsigned integer in base 10.
      Parameters:
      octalStr - an octal value to be converted to a decimal string.
      Returns:
      the string representation of the octal value in decimal (base 10).
      Since:
      3.1.0