Package com.singularsys.jep.misc.functions

# Class FromBase

java.lang.Object
com.singularsys.jep.functions.PostfixMathCommand
com.singularsys.jep.functions.NaryFunction
com.singularsys.jep.misc.functions.FromBase

All Implemented Interfaces:
  `PostfixMathCommandI`, `Serializable`

public class FromBase extends NaryFunction
PostfixMathCommand which converts a string to a number in a given base. Instance of these classes can be specified with two different behaviours either with the base specified in the constructor or with no base specified in which case the function requires two arguments, the second of which is the base. A third form allows a prefix to be specified, this prefix must be present in the Jep expression.

For example

    jep.addFunction("fromDec",new FromBase(10));
     jep.parse("fromDec(\"123.45\")");
     jep.addFunction("fromHex",new FromBase(16,"0x"));
     jep.parse("fromHex(\"0xff\")");
     jep.addFunction("fromBase",new FromBase());
     jep.parse("fromBase(\"0377\",8)");

Author:
  Rich Morris Created on 02-May-2005
See Also:
  - Serialized Form

- ## Field Summary

  ### Fields inherited from class com.singularsys.jep.functions.PostfixMathCommand

  `curNumberOfParameters, description, name, NaN, numberOfParameters`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `FromBase()`
  `FromBase(int base)`
  `FromBase(int base, String prefix)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Object`
  `eval(Object[] args)`
  Evaluate the function
  `Object`
  `fromBase(String str, int base)`

  ### Methods inherited from class com.singularsys.jep.functions.NaryFunction

  `run`

  ### Methods inherited from class com.singularsys.jep.functions.PostfixMathCommand

  `asArray, asBool, asDouble, asInt, asLong, asStrictInt, asString, asType, checkNumberOfParameters, getDescription, getDescription, getDescriptionWithType, getName, getNumberOfParameters, setCurNumberOfParameters, setDescription, setName, toString, toString`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### FromBase

    public FromBase()

  - ### FromBase

    public FromBase(int base)

  - ### FromBase

    public FromBase(int base, String prefix)

- ## Method Details

  - ### eval

    public Object eval(Object[] args) throws EvaluationException
    Description copied from class: `NaryFunction`
    Evaluate the function
    Specified by:
      `eval` in class `NaryFunction`
    Parameters:
      `args` - arguments to the function
    Returns:
      value returned by the function
    Throws:
      `EvaluationException` - if the calculation cannot be performed

  - ### fromBase

    public Object fromBase(String str, int base) throws NumberFormatException
    Throws:
      `NumberFormatException`