highest or lowest variable in an array; how do you find it?


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Dec 2009
    Location
    Kalamazoo
    Posts
    42

    Default highest or lowest variable in an array; how do you find 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

  2. #2
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default Re: highest or lowest variable in an array; how do you find 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
    http://www.scalerobotics.com

  3. #3
    Join Date
    Oct 2004
    Posts
    440


    Did you find this post helpful? Yes | No

    Default Re: highest or lowest variable in an array; how do you find it?

    Quote Originally Posted by DDDvvv View Post
    Hi everyone.
    im trying to determine the highest and lowest variable in a 50 byte array. whats the easiest way to do it?
    yArray VAR BYTE[50]
    yLow VAR BYTE
    yLow = 255
    yHigh VAR BYTE
    yHigh = 0
    i VAR BYTE

    FOR i = 0 TO 49
    IF yArray[i] < yLow THEN
    yLow = yArray[i]
    endif
    IF yArray[i] > yHigh THEN
    yHigh = yArray[i]
    ENDIF
    NEXT


    Not being duplicative just that ScaleRobotics Posted First.

    Norm
    Last edited by Normnet; - 12th July 2012 at 21:53.

  4. #4
    Join Date
    Nov 2009
    Location
    London
    Posts
    251


    Did you find this post helpful? Yes | No

    Default Re: highest or lowest variable in an array; how do you find it?

    I'll take a shot at it as well, but the gurus have already replied, this is just a little different.

    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
    ScaleRobotics, I hope you had good internet free holidays

  5. #5
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: highest or lowest variable in an array; how do you find it?

    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

  6. #6
    Join Date
    Nov 2009
    Location
    London
    Posts
    251


    Did you find this post helpful? Yes | No

    Default Re: highest or lowest variable in an array; how do you find it?

    OOps, my mistake. Instead use the following:

    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 Dave for correcting me
    Last edited by Megahertz; - 13th July 2012 at 18:10.

  7. #7
    Join Date
    Dec 2009
    Location
    Kalamazoo
    Posts
    42


    Did you find this post helpful? Yes | No

    Default Re: highest or lowest variable in an array; how do you find it?

    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

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts