# Class: com.pnfsoftware.jeb.util.encoding.Conversion

Utility methods for safe conversions of strings or boxed representations of numbers, to numbers. Base 10, 16 and 8 are supported. Numbers in bases 16 and 8 require explicit prefix or suffix. Otherwise, it is assumed that the string represents a number in base 10. The exceptions are: 
 
- Strings starting with "0x" or ending with "h": assume base 16
-  
- Strings starting with "0?" \(? denoting any character\): assume base 8
-

## Constructor: Conversion


## Static Method: getHexPossibility
- parameter: `s`, type: `java.lang.String`
- return type: `int`

Description: Determine if a string may, must, or cannot be representing a hexadecimal number.
parameter: s: prefix\-less, suffix\-less string representation of a number
return: 0=cannot, 1=may, 2=must \(be a hex number\)

## Static Method: stringToInt
- parameter: `s`, type: `java.lang.String`
- parameter: `def`, type: `int`
- parameter: `defaultBase`, type: `int`
- return type: `int`

Description: Convert to int.
parameter: s: input string
parameter: def: the default value
parameter: defaultBase: the base to use if no prefix or suffix determines one
return: the converted value or the default value on error

## Static Method: stringToInt
- parameter: `s`, type: `java.lang.String`
- parameter: `def`, type: `int`
- return type: `int`

Description: Convert to int. The default conversion base, if undetermined, will be 10.
parameter: s: input string
parameter: def: value to be returned on error
return: the converted value

## Static Method: stringToInt
- parameter: `s`, type: `java.lang.String`
- return type: `int`

Description: Convert to int. The default conversion base, if undetermined, will be 10.
parameter: s: input string
return: the converted value, 0 on error

## Static Method: stringToIntUnsafe
- parameter: `s`, type: `java.lang.String`
- return type: `java.lang.Integer`

Description: Convert a string to an integer, using base 10 when no prefix or suffix determines the base.
parameter: s: input string
return: the converted value, or null if conversion failed
throws: currently not thrown; retained for compatibility

## Static Method: stringToLong
- parameter: `s`, type: `java.lang.String`
- parameter: `def`, type: `long`
- parameter: `defaultBase`, type: `int`
- return type: `long`

Description: Convert to long.
parameter: s: the input string
parameter: def: the default value if the conversion failed
parameter: defaultBase: the default base if the base representation could not be determined
return: the converted value or the default value on error

## Static Method: stringToLong
- parameter: `s`, type: `java.lang.String`
- parameter: `def`, type: `long`
- return type: `long`

Description: Convert to long. The default conversion base, if undetermined, will be 10.
parameter: s: input string
parameter: def: value to be returned on error
return: the converted value

## Static Method: stringToLong
- parameter: `s`, type: `java.lang.String`
- return type: `long`

Description: Convert to long. The default conversion base, if undetermined, will be 10.
parameter: s: input string
return: the converted value, 0 on error

## Static Method: stringToLongUnsafe
- parameter: `s`, type: `java.lang.String`
- return type: `java.lang.Long`

Description: Convert a string to a long, using base 10 when no prefix or suffix determines the base.
parameter: s: input string
return: the converted value, or null if conversion failed

## Static Method: toInt
- parameter: `o`, type: `java.lang.Object`
- return type: `int`

Description: Best effort conversion of an object to an integer. If the conversion fails, the value returned is 0.
parameter: o: a [String](String) or an [Integer](Integer)
return: the converted int

## Static Method: toInt
- parameter: `o`, type: `java.lang.Object`
- parameter: `def`, type: `int`
- return type: `int`

Description: Best effort conversion of an object to an integer.
parameter: o: a [String](String) or an [Integer](Integer)
parameter: def: default value to return if the conversion fails
return: the converted int

## Static Method: toLong
- parameter: `o`, type: `java.lang.Object`
- return type: `long`

Description: Best effort conversion of an object to an integer. If the conversion fails, the value returned is 0.
parameter: o: a [String](String) or an [Long](Long)
return: the converted long

## Static Method: toLong
- parameter: `o`, type: `java.lang.Object`
- parameter: `def`, type: `long`
- return type: `long`

Description: Best effort conversion of an object to a long.
parameter: o: a [String](String) or an [Long](Long)
parameter: def: default value to return if the conversion fails
return: the converted long

