I will answer using Python, but the underlying method can be easily adapted to another language.
You can represent the mapping you describe in your question
1 -> 0
3 -> 1
0 -> 2
2 -> 3
as a map, or a Python dictionary in this case (it can also be represented as a simple array, but this complicates a little bit the code):
logical2hardware_mapping = {0: 1, 1: 3, 2: 0, 3: 2}
From this map representation, you can post-process your result quite easily by re-arranging the bits:
import typing as ty
def rearrange_hardware_result(hardware_result: str, mapping: ty.Dict[int, int]) -> str:
# 1. Invert the mapping
hardware2logical_mapping = {v: k for k, v in mapping.items()}
# 2. Construct the rearranged result
return "".join(
hardware_result[hardware2logical_mapping[i]]
for i in range(len(hardware_result))
)
Finally, you can test the function on your example and check that it works as expected:
hardware_result = "1010"
print(rearrange_hardware_result(hardware_result, logical2hardware_mapping))
# Output "1100"
Side note: I worked quite a bit with these issues of mapping and how to change them. The most important thing to do at the very beginning in order to understand what you are doing is to note somewhere what is represented. For example in your mapping, you do not explicitly say what the indices on the left-hand side of the arrows are, same for the right-hand side ones. Once the meaning of the indices you are using is clear, everything starts to become easier.