Each hexagram has two positions: one in the binary natural order (0-63), and one in the King Wen sequence. The rule is: a hexagram moves from its natural order position to its King Wen position. For example, Qian is at position 63 in the natural order and position 0 in the King Wen sequence, so σ(63)=0. Then look at position 0 (Kun), which is at position 1 in the King Wen sequence, so σ(0)=1. Follow this chain until you return to the start. There is no formula — σ is defined by the mapping table between the two orderings.