How does the Serial monitor display '12594' when we write Serial.print('12');?I have used single quotes intentionally.
[code]
void setup()
{
Serial.begin(9600);
Serial.print('12');
}
void loop()
{
}
[/code]
How does the Serial monitor display '12594' when we write Serial.print('12');?I have used single quotes intentionally.
[code]
void setup()
{
Serial.begin(9600);
Serial.print('12');
}
void loop()
{
}
[/code]
when you output '12' your outputting 2 characters, a '1' and then a '2', this results in hex 31 or dec 49 being transmitted followed by a 32hex / 50dec, if you concatinate the two into a single integer then you get 12594, sending the 10 works out to be 12592, 11=12593
the print statement is interpreting this as an integer (16bits) instead of two 8 bit characters because in C the character literal is defined as an int and your providing just the right number of 8 bit characters to make an int
if you want to send the string literal "12" then you need the double quotes, this will also terminate the string correctly in the code so the actual memory used in this case would be 3 bytes '1','2','/0'
hope that helps
when you output '12' your outputting 2 characters, a '1' and then a '2', this results in hex 31 or dec 49 being transmitted followed by a 32hex / 50dec, if you concatinate the two into a single integer then you get 12594, sending the 10 works out to be 12592, 11=12593
the print statement is interpreting this as an integer (16bits) instead of two 8 bit characters because in C the character literal is defined as an int and your providing just the right number of 8 bit characters to make an int
if you want to send the string literal "12" then you need the double quotes, this will also terminate the string correctly in the code so the actual memory used in this case would be 3 bytes '1','2','/0'
hope that helps