Shop OBEX P1 Docs P2 Docs Learn Events
Clarification of .BYTE required — Parallax Forums

Clarification of .BYTE required

BasilBasil Posts: 380
edited 2009-03-07 09:43 in Propeller 1
Hi All,

Quick question. Is my understanding of the .byte command correct?

When using the commans 'Variablename.byte[noparse][[/noparse]x]', are the bytes arranged as follows within the long? (or word)

[noparse][[/noparse]byte3][noparse][[/noparse]byte2][noparse][[/noparse]byte1][noparse][[/noparse]byte0]
and within a byte [noparse][[/noparse]bit7...bit0]

or is it [noparse][[/noparse]byte0][noparse][[/noparse]byte1][noparse][[/noparse]byte2][noparse][[/noparse]byte3]?

Thanks [noparse]:D[/noparse]

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
-Alec

Velden in N scale

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-03-07 02:51
    The least significant byte is first (byte[noparse][[/noparse] 0 ]) and the most significant byte is last (byte[noparse][[/noparse] 3 ]).

    This is what is known as "little endian" because the "little" end of the word comes first.
  • BasilBasil Posts: 380
    edited 2009-03-07 03:42
    Thanks Mike [noparse]:)[/noparse] Futher to this question :P

    Lets say I have an array 'long ary[noparse][[/noparse]10]

    Can I perform val := ary.byte[noparse][[/noparse]7] to get the 7th byte from end of the array? (ie byte 3 of the 2nd to last element)
    The end would be byte 0 of the 10th element I would guess.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Alec

    Velden in N scale
  • Mike GreenMike Green Posts: 23,101
    edited 2009-03-07 03:56
    ary.byte[noparse][[/noparse] 7 ] is the 8th byte of the array, the most significant byte of the 2nd long of the array. The last byte of the array is ary.byte[noparse][[/noparse] 39 ] because there are 10 longs, each with 4 bytes and the 1st element is subscript zero.
  • BasilBasil Posts: 380
    edited 2009-03-07 04:00
    Oh, sorry. Thats what I meant but I think you answered my question [noparse]:)[/noparse]

    So really, .byte is simply an offset to a pointer beginning at the least significant byte in the last element in an array and working towards the most significant byte in the 0'th element.

    EDIT: I guess I could just show you what I want to do and check if its right :P I Asked these questions so I could learn...
    Here's what I'm trying to achieve.
    EDIT 2: I think I just found a better way to do this :P Questions finished

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Alec

    Velden in N scale

    Post Edited (Basil) : 3/7/2009 4:50:04 AM GMT

  • Mike GreenMike Green Posts: 23,101
    edited 2009-03-07 05:22
    Nope

    The data is laid out in memory like this:
    Long 0 Byte 0, Long 0 Byte 1, Long 0 Byte 2, Long 0 Byte 3,
    Long 1 Byte 0, Long 1 Byte 1, Long 1 Byte 2, Long 1 Byte 3,
    Long 2 Byte 0, ...

    Long n Byte 0, Long n Byte 1, Long n Byte 2, Long n Byte 3

    Byte[noparse][[/noparse] m ] simply references the bytes in the above order
    with Byte 3 of one Long followed by Byte 0 of the next Long
    and the bytes numbered sequentially starting at zero.
  • BasilBasil Posts: 380
    edited 2009-03-07 09:43
    Oh [noparse]:)[/noparse] Im all back to front then! Thanks Mike for showing it visually, im a visual person.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Alec

    Velden in N scale
Sign In or Register to comment.