parse_int#

hexrec.utils.parse_int(value)[source]#

Parses an integer.

Parameters:

value (Union[str, Any]) – A generic object to convert to integer. In case value is a str (case-insensitive), it can be either prefixed with 0x or postfixed with h to convert from a hexadecimal representation, or prefixed with 0b from binary; a prefix of only 0 converts from octal. A further suffix applies a scale factor as per SUFFIX_SCALE. A None value evaluates as None. Any other object class will call the standard int().

Returns:

int – None if value is None, its integer conversion otherwise.

Examples

>>> parse_int('-0xABk')
-175104
>>> parse_int(None) is None
True
>>> parse_int(123)
123
>>> parse_int(135.7)
135