Stupid question -> copy long to byte
average joe
Posts: 795
This is a really dumb question, I know. There's gotta be a better way to do this.
var long slong[2] byte dbyte [8] PUB copy repeat t from 0 to 4 byte[@dbyte][t] := byte[@slong][3-t] repeat t from 0 to 4 byte[@dbyte + 4][t] := byte[@slong + 4][3-t]
Comments
I can't think of a good way to do this myself, but I do know you want your "t" values to go from zero to three not zero to four.
I think there's a ".byte" command in Spin that could help. I haven't found need of it myself.
Do you want to tell us why you want to rearrange the bytes? Someone might have easier way to do what you want.
Of course if you don't need the bytes rearranged, you could just use the bytemove command.
If you do use this technique to rearrange longs, you'll probably want to make your algorithm a method. The method would called with two parameters. These parameters would be a pointer to the long to be rearranged and a pointer to the first byte where the four bytes are to be stored.
Using a method would simplify the code a bit though I agree there is likely an easier way to do this.
A bit more on what's going on. So I'm receiving an xbee's 64 bit address as two longs (hex). I then want to transmit that address back over the xbee. I'm re-arranging the bytes during the copy so they are easier to read "off the wire." I think the key is the .byte command. Still, what I have works for now, even if it's not the most "correct" way. As always, bigger fish to fry...