Hi everyone.
im trying to determine the highest and lowest variable in a 50 byte array. whats the easiest way to do it?
Hi everyone.
im trying to determine the highest and lowest variable in a 50 byte array. whats the easiest way to do it?
NAG CON WIFE!
WIFE VAR MOOD
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
http://www.scalerobotics.com
Last edited by Normnet; - 12th July 2012 at 20:53.
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 holidaysCode: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"....
Dave Purola,
N8NTA
EN82fn
OOps, my mistake. Instead use the following:
Thanks Dave for correcting meCode: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
Last edited by Megahertz; - 13th July 2012 at 17:10.
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.
NAG CON WIFE!
WIFE VAR MOOD
Bookmarks