and, if i send "123", output is like:
49
50
51
1
2
3
but....if i take off this line Serial.println(buffer[i]); (which is found in the for routine in the above code, it stops working and i get data like:
1
15
15
2
3
15
(data sent is still "123"). I have no idea why this happens! Btw, 0xf is 15 in decimal.
Because the "ln" bit of the print statement tells the computer to output the ASCII codes that put it on a new line, that is a carriage return and a line feed. (CR & LF)
Serial.read() returns -1 (0xffff) if there is no character available. You are probably seeing the masked-off 0xf from the -1.
Suppose Serial.available() returns 1 and there really is only one character available. Then the code reads three bytes. One will be the value, and two will be (int) -1, thus printed as 15.