I have to find a way to send two variables between 1 and 8 between two robots, but the IR function only allows one. Is there a way to make a number out of these two that can be easily transformed back into the original variables ?
For example, if var1=5 and var2=7, I want to be able to make a var3 that is easily transformed back into var1=5 and var2=7 for the robot.
Just for information, the robot I use is a ThymioII, it's documentation can be found there : https://www.thymio.org/en:asebalanguage
To expand on Juanito's suggestion, if you encode like so:
Then you can decode like so:
This assumes that the
/operator in Aseba is integer division rounding down.If you prefer to work in binary, you can take advantage of the fact that Aseba integers are $16$ bits wide to encode with shifts:
And decode:
The first scheme will be more convenient if you will need to print out or otherwise debug the values of $c$ in decimal notation, so that $a=5$ and $b=7$ gets encoded as
57. The second scheme will be more convenient if you'll be viewing values in hexadecimal, so that $a=5$ and $b=7$ gets encoded as0x0507.