Lets put it in parts.
I got a socket receiving data OK and I got it in the \x31\x31\x31 format.
I know that I can get the same number, ripping the \x with something like
for i in data: print hex(ord(i))
so I got 31 in each case.
But if I want to add 1 to the data (so it shall be “32 32 32“)to send it as response, how can I get it in \x32\x32\x32 again?
The “\x31” is not a format but the text representation of the binary data. As you mention ord() will convert one byte of binary data into an int, so you can do maths on it.
To convert it back to binary data in a string, you can use chr() if it’s on just one integer. If it’s many, you can use the %c formatting character of a string:
However, a better way is probably to use struct.
You may even want to take a look at ctypes.