I am using a joystick controller that sends over a zigbee Terminal from a java application. So I am controlling a servo degree in a vehicle, so this degree is 65=<degree<=115, And I am buffering for 3 chars as if i received 2 digits Integer it would be 065 or if i received 3 digits Integer it would be 115. Then I directly write this value to the servo. I know I can do a condition to check for the first received digit, if it's zero then i would use the only last two values, But I am caring about complexity that's it. Any Ideas ?
I use sprintf() to convert data types to formatted strings. If you want a specific number of leading zeros, try this. It insures there are three characters, and if not, it adds the correct number of leading zeros.
int myInt = 12;
char outBuf[16];
sprintf(outBuf,"%03u",myInt);
Serial.println(outBuf);
For transmission, a leading space takes up exactly the same amount of space. For use on the receiver, the leading space is much easier to deal with than a leading 0, because a leading 0 is how functions that convert strings to numeric values know that you want the number interpreted as an octal value.
It is unlikely that you will be sending values less than 100 as octal, while sending values greater than or equal 100 as decimal.
PaulS:
For transmission, a leading space takes up exactly the same amount of space. For use on the receiver, the leading space is much easier to deal with than a leading 0, because a leading 0 is how functions that convert strings to numeric values know that you want the number interpreted as an octal value.
It is unlikely that you will be sending values less than 100 as octal, while sending values greater than or equal 100 as decimal.
Unless you are really weird, that is.
HAHA I understood you :D, And yes I agree with you
SurferTim:
I use sprintf() to convert data types to formatted strings. If you want a specific number of leading zeros, try this. It insures there are three characters, and if not, it adds the correct number of leading zeros.