def parse_literal(literal: str) -> int:
    """
    Parses a literal (aka "1234" or "$A0F" or "%1001")

    >>> parse_literal('$BA1')
    2977

    >>> parse_literal('%01010111')
    87

    >>> parse_literal('57')
    57

    >>> parse_literal('400')
    400

    >>> parse_literal('-100')
    -100

    >>> parse_literal('-1')
    -1

    :param literal: A string containing the literal to parse
    :return: The parsed literal (a bytearray type)
    """
    if literal[0] == '$':  # Parsing a hex literal
        if len(literal) % 2 == 0:
            literal = literal[0] + '0' + literal[1:]

        return int(literal[1:], 16)
    if literal[0] == '%':  # Parsing a binary literal
        assert (len(literal) - 1) % 4 == 0  # Has to be divisible by 4 to convert into hex
        hexed = hex(int(literal[1:], 2))[2:]
        if len(hexed) % 2 == 1:
            hexed = '0' + hexed

        return int(hexed, 16)

    # Integer literal

    hexed = hex(int(literal)).replace('0x', '')

    #if len(hexed) % 2 == 1:
        # Odd length string, add 0 to the beginning
        #hexed = '0' + hexed

    return int(hexed, 16)