Clarification of .BYTE required
Basil
Posts: 380
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
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
This is what is known as "little endian" because the "little" end of the word comes first.
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
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
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.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
-Alec
Velden in N scale