Hi everyone.
im trying to determine the highest and lowest variable in a 50 byte array. whats the easiest way to do it?
Printable View
Hi everyone.
im trying to determine the highest and lowest variable in a 50 byte array. whats the easiest way to do it?
Here's one way:
Code:i var byte
lowest var byte
highest var byte
myarray var byte[50]
'then do something to fill array with data
lowest = 255
highest = 0
for i = 0 to 49
if myarray[i] < lowest then lowest = myarray[i]
if myarray[i] > highest then highest = myarray[i]
next i
I'll take a shot at it as well, but the gurus have already replied, this is just a little different.
ScaleRobotics, I hope you had good internet free holidays :)Code:i var byte
lowest var byte
highest var byte
myarray var byte[50]
for i = 0 to 48
Highest= MyArray[i] MAX MyArray[i+1]
Lowest= MyArray[i] MIN MyArray[i+1]
next i
I don't think Megahertz code will work as it is resetting the maximum and minimum value each pass thru the loop. NO testing is being done against the variables "Highest" and "Lowest"....
OOps, my mistake. Instead use the following:
Thanks Dave for correcting me :)Code:i var byte
lowest var byte
highest var byte
CheckHigh Var Byte
CheckLow Var Byte
myarray var byte[50]
CheckHigh=0 : CheckLow=255
for i = 0 to 48
CheckHigh= MyArray[i] MAX MyArray[i+1]
If CheckHigh>Highest then Highest=CheckHigh
Lowest= MyArray[i] MIN MyArray[i+1]
If CheckLow<Lowest then Lowest=CheckLow
next i
thanks guys .
i was thinking of doing it like post #2, and i thought there was an easier way to skin it. this really helps alot with all this options.:smile: