I found a small problem that is more or less frustrating...
The ATmega328 is 16-bit and can therefore handle numbers up to 65'535, but not further.
The long data type requires 32-bit so the CPU handles it a bit differently.
(Theres also a long long data type which is 64-bit, but the same problem appears on that one)
If I declare a long long variable I can use it to calculate all and all no big problems
long long num = 5000;
num += 2000;
Serial.println(word(num));
Gives out 7000 in respond.
But I have to convert the number to string to send it, therefore the word() function. But even if I print it on a LCD or anything it still got the problem.
Now the problem is as follows: if the number is above 65535 it "resets" back to 0, or if you got some rest it gets added. For example
65535L + 5L
gives 4 (it includes the 0) because it's actually 65536 (2^16) + 4.
You can check the "real" value for example
floor( 80000L / 65536L )
gives 1, so they are not exactly reset; it's just that when you get the string form of the long it can't handle numbers bigger then 65535 (which is max from 16-bit, aka 11111111 11111111 in binary is 65535 in decimal).
What? I should note that I can not use the serial because my IDE crashes when it gets multiple serial messages (I do not know why nor how to fix it). I am using my raspberry pi because my windows cant launch the IDE.
tack:
Why did you show a serial.Print example in your first post then and quote certain outputs from the sketch you posted?
BECAUSE I am not wondering how to fix my serial shit. I gave you the principal and the question on how to fix this problem. Please stay related to my main question here!
tack:
Why did you show a serial.Print example in your first post then and quote certain outputs from the sketch you posted?
BECAUSE I am not wondering how to fix my serial shit. I gave you the principal and the question on how to fix this problem. Please stay related to my main question here!
I gave you the answer. You are in error. word() is a cast, nothing to do with strings. You cast your variable to word datatype (16 bit) before output, so why would it be anything else?
With that attitude, I'm outta here. Good luck with any future help. I don't owe you my free time so I will donate it to someone more appreciative.
tack:
I gave you the answer. You are in error. word() is a cast, nothing to do with strings. You cast your variable to word datatype (16 bit) before output, so why would it be anything else?
With that attitude, I'm outta here. Good luck with any future help. I don't owe you my free time so I will donate it to someome more appreciative.
I am bloody sorry but I am sure you know how someones attitude can get messy when they are frustrated. I just bought this arduino kit and almost nothing of it is working.
Now I removed all the word() stuff but I am still getting the problem where it is going to 0 when it reaches 65536.
Why "long long"?
a range of -9223372036854775808 to +9223372036854775807 is fairly rarely required.
Even a "long" is going to take about 20 minutes to rollover (estimate/guess).