I have been looking to concat two int but with no luck.
My project is reading from a RTC module I have the time in hour & minutes.
The Var below gets the time from the clock lets say the time is 13:42
int NewTimeHr = now.hour();
int NewTimeMin = now.minute();
I try to concat the two numbers together by doing the following (this found on another post)
int NowTime = NewTimeHr*10+NewTimeMin;
If I do a Serial.print(NowTime); You would think the answer is 1342
But no I get 172. I don't know why it's adding only the first digit of the second variable to my first var. e.g. 13 + 4 = 17 How do I get the two int as one number without adding them together?
What you're doing there is not really concatenating - that refers to combining strings.
What you're doing is just plain old math - addition and multiplication - to result in a number with the hours in the thousands and hundreds place, and the minutes in the tens and ones place. Which when printed looks the same as if you'd concatenated the hours and minutes.
If the second value was only one digit, you would probably want to multiply the first value by 10 instead.
DrAzzy:
What you're doing there is not really concatenating - that refers to combining strings.
What you're doing is just plain old math - addition and multiplication - to result in a number with the hours in the thousands and hundreds place, and the minutes in the tens and ones place. Which when printed looks the same as if you'd concatenated the hours and minutes.
If the second value was only one digit, you would probably want to multiply the first value by 10 instead.
The assumption is the output should 'resemble' 24 hour clock military time, but the hour's leading zero would be lost.