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?

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

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums