def reverse_index(index, length):
    """
    Reverse the passed in index as if the index direction was flipped.

    Taking the string "hello" as an example the regular indexes for
    each letter are::

        01234
        hello

    Reversing the indexes yields::

        43210
        hello

    This allows easily indexing into a bitdef on bitdef indexing terms.

    Args:
        index (int): The index position to reverse.
        length (int): The length of the array being indexed into.
    Returns:
        int: The reversed index.
    """

    return length - index - 1