Shop OBEX P1 Docs P2 Docs Learn Events
byte access of array longs Question — Parallax Forums

byte access of array longs Question

Rick_HRick_H Posts: 116
edited 2011-10-03 00:24 in Propeller 1
I want to parse through some longs to transmit to my VB application.

What would be a good loop structure for this?
Var
long    flag3, mandarin[6], op1[5], op2[5], op3[5], op4[5], op5[5], op6[5]
long    dataout[256]

pub Data | index 1, index2

repeat index1 from 144 to 0
            dataout[index1] := mandarin[0].Byte[index1]

I know this isn't right. I need to put each var in order into bytes to transmit to VB.net and then reassemble them into longs. The VB part is easy I just can't seam to get this straight into my head. if I reference Mandarin[0] will index5 be the lsb of mandarin[1]? or am I going about this all the wrong way?

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2011-10-01 22:56
    The LSB of mandarin[1] would actually be index 4 (0 based) but otherwise it's OK. Just drop the [0] (invalid), e.g. mandarin.byte[index1].
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2011-10-01 22:59
    Rick_H,

    Yes, and no... your data read line needs to look like this... BYTE[@mandarin][index1] ... Index5 though would be ls-byte of mandarin[1] assuming that index5 would actually equate to a value of 4 ... remember 0 counts... so ...

    BYTE[@mandarin][0] equals mandarin[0] byte 0
    BYTE[@mandarin][1] equals mandarin[0] byte 1
    BYTE[@mandarin][2] equals mandarin[0] byte 2
    BYTE[@mandarin][3] equals mandarin[0] byte 3

    BYTE[@mandarin][4] equals mandarin[1] byte 0
    BYTE[@mandarin][5] equals mandarin[1] byte 1
    BYTE[@mandarin][6] equals mandarin[1] byte 2
    BYTE[@mandarin][7] equals mandarin[1] byte 3

    might also want to change the dataout[256] declaration to byte rather than long.
  • Rick_HRick_H Posts: 116
    edited 2011-10-01 23:01
    ahh ok I got ya, and this will parse all 144 in order correct? so index 24 would be op1[0] lsb?

    ya sorry that was a typo, I wast more memory that way :)
  • kuronekokuroneko Posts: 3,623
    edited 2011-10-01 23:04
    Rick_H wrote: »
    ahh ok I got ya, and this will parse all 144 in order correct? so index 24 would be op1[0] lsb?
    Yes, as long as you keep the long arrays in that order.
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2011-10-01 23:26
    Just keep in mind that the data within each long is stored in little Endian meaning...

    i.e. LONG = [Byte3 Byte2 Byte1 Byte0]

    the byte reference to the long is

    Base Address+0 Byte0
    Base Address+1 Byte1
    Base Address+2 Byte2
    Base Address+3 Byte3

    in Big-Endian it would look like this

    Base Address+0 Byte3
    Base Address+1 Byte2
    Base Address+2 Byte1
    Base Address+3 Byte0
  • Rick_HRick_H Posts: 116
    edited 2011-10-02 00:25
    Thanks guys I get it now, it works but I think I am gonna try and rearrange my var's. its turning into a parsing nightmare.
  • JonnyMacJonnyMac Posts: 9,203
    edited 2011-10-02 13:31
    Would nested loops make implementation easier, and more obvious?
    repeat lidx from 0 to 5
        repeat bidx from 0 to 3
          mybyte := larray[lidx].byte[bidx]
    
  • Rick_HRick_H Posts: 116
    edited 2011-10-03 00:24
    I am not lookinh for obvious, I am just dumping all my data to pc and I can sort it out on that end. I'm continually dumping 96 longs over usb to my VB app.
Sign In or Register to comment.