import re


def pin_value(value):
    """Convert pin number into value (especially for BGA numbering scheme)"""

    res = re.match(r'[~0-9A-Z]+', value)
    if res:
        _sum = 0
        for _chr in res.group(0):
            _sum = _sum * 128 + ord(_chr)
        return _sum
    raise ValueError("'{}' is no valid pin value".format(value))