I need to generate a "package" (string) that consists in 3 velocities: xvel, yvel and wvel. The most convenient way to do so, is to multiply them by 100 and the convert them to hex. The problem is that I need a constant length in each velocity (in order to easily decode them after). I designed the following code, but I have no success when trying to concatenate every vector in a single "buffer". Any suggestions?
string buffer [50];
int x = 1.23*100;
int y = 0*100;
int w = 7.89*100;
string xPadle = "";
string yPadle = "";
string wPadle = "";
if(x <= 15) string xPadle = "00";
else if(x <= 255) string xPadle = "0";
else string xPadle = "";
if(y <= 15) string yPadle = "00";
else if(y <= 255) string yPadle = "0";
if(w <= 15) string wPadle = "00";
else if(w <= 255) string wPadle = "0";
sprintf (buffer, "%s%x%s%x%s%x", xPadle, x, yPadle, y, wPadle, w);
//printf("%s", buffer);
return 0;