Serial print sends the ASCII character codes. The ASCII characer code for '2' is 5010 (0x32 hex). If you want to send the byte 2 use Serial.write(). That sends the binary number (0x02). If you want a number (2) displayed when received from a print (50 dec), subtract '0' (0x30 or 40 dec) from the received character.
I was thinking that I should point out that subtracting '0' only works with single characters, '0' to '9'. So a better example is:
char receivedChar = '7'; // try this with a non numeric character, say 'e'
void setup()
{
Serial.begin(115200);
// check to maake sure that the receivedChar
// is a valid number 0 to 9.
if(receivedChar >= '0' && receivedChar <= '9')
{
int val = receivedChar - '0';
Serial.print(" val = ");
Serial.println(val);
}
else
{
Serial.println("invalid input");
}
}
void loop()
{
}