A lexicographic binary encoding and a python implementation