Shop OBEX P1 Docs P2 Docs Learn Events
Two dimensional array? — Parallax Forums

Two dimensional array?

EdKirkEdKirk Posts: 27
edited 2006-06-05 15:04 in Propeller 1
I would like to display on my monitor 5 rows of 7 numbers each.

Please see my desired example, but cannot load the 2-D array.

EdKirk·· edk@wi.rr.com

Comments

  • kerrywkerryw Posts: 61
    edited 2006-06-05 03:56
    I don't know that spin supports multidimensional arrays. I couldn't find any examples in the docs. You can easily mimic it though if spin doesn't:

    long Number[noparse][[/noparse]5*7] 'create a single dimesional array that stores the equivalent of a two-dimensional array

    Repeat Rows From 1 to 5
    __Repeat Cols From 1 to 7 'I noticed in your code sample that you have 'Rows' in this line, not 'Cols'
    ____VideoDisplay.dec(Number[noparse][[/noparse](Rows*5)+Cols]) 'here is where we mimic the 2 dimensional array, basically doing what a compiler does in languages that support multidemsional arrays
    ____VideoDisplay.out(32)
    .....

    Hope this helps.

    Kerry

    Post Edited (kerryw) : 6/5/2006 4:01:48 AM GMT
  • EdKirkEdKirk Posts: 27
    edited 2006-06-05 11:42
    Kerry,

    Very clever! I will do a 'long' to store two 16-bit numbers.

    Why not four 8-bit numbers? How do it know? Things usually fall down; how do it know? I will never understand gravity.

    Ed Kirkham
    edkirk edk@wi.rr.com


    Kerry,

    Never mind my stupid question.· I thot at first that you were splitting the 32-bit numbers in half; but no you just made the list longer instead.·

    Since I do not need 32-bit resolution for my numbers I guess I could have used 'word' instead of 'long'.

    Ed


    Post Edited (EdKirk) : 6/5/2006 12:32:52 PM GMT
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2006-06-05 15:04
    EdKirk,


    Not a stupid question, you could actually split the 32-bit numbers in half to store your numbers.... likewise for splitting it in 4ths. Sort of like BCD format.


    Long NumberArray[noparse][[/noparse]10]


    ...could represent 20 16-bit numbers or 40 8-bit numbers, but since you can specify a descriptor of long, word, or byte, the conversion
    is partially done for you.

    In terms of occupying memory...
    long NumberArray[noparse][[/noparse]10] = word NumberArray[noparse][[/noparse]20] = byte NumberArray[noparse][[/noparse]40]


    The remainder of the conversion is to do what kerryw suggests. You could expand this further to a 3-dimentional array or whatever met your needs...

    X = 5     'Rows
    Y = 7     'Columns
    Z = 3     'Depth
    
    word Number[noparse][[/noparse]X*Y*Z]     '105
    
    
    Repeat Zz From 0 to Z-1 
      Repeat Yy From 0 to Y-1
        Repeat Xx from 0 to X-1
          VideoDisplay.dec(Number[noparse][[/noparse] Zz*(X*Y) + Yy*X + Xx + 1 ] )
          VideoDisplay.out(32)
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 6/5/2006 3:07:30 PM GMT
Sign In or Register to comment.