newbie C syntax help
hi all, noob.
i playing around servo example , came across code.
switch(ch) {
case '0'...'9':
v = v * 10 + ch - '0';
break;
can explain why necessay have '0' correct input v serial port?
i playing around servo example , came across code.
switch(ch) {
case '0'...'9':
v = v * 10 + ch - '0';
break;
can explain why necessay have '0' correct input v serial port?
because char '0' '9' have binary values 48 57. if want add numeric value need subtract '0' or 48 without quote. i.e: char '5' equals 53 in binary if subtract 48 or '0' 53 binary value 5 (53- 48 = 5), need in v = v * 10 + ch - '0'; expression. same v = v * 10 + 5.
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > newbie C syntax help
arduino
Comments
Post a Comment