UBYTE/FOR loop issue?
The code compiles and runs, but it never ends. When the loop gets to 255, it begins again from 0.
Making the loop "0 to 254" or changing i to an INTEGER/UINTEGER gets around the issue.
LTee wrote:Aha, I see - thanks for that. The thought had occurred to me that perhaps this was unavoidable, but it's nice to know for sure. Thanks for the info and the pointers!
While we're here and talking about types, could anyone tell me if there's a more elegant way to do this?
I have three UBYTES with values. I want to add them up, divide by three to get an average, and put the result into another UBYTE. However, I can't just do the maths with the UBYTES because the addition takes the value > 255 and information is lost.
I came up with this solution:
[...] (Code)
... but it seems kind of messy. Is there a way to do that better?
I suppose the easiest way would be to store the three values as UINTEGERs to begin with and then cast to UBYTE at last minute, after the calculation?
Users browsing this forum: No registered users and 1 guest