Shop
OBEX
P1 Docs
P2 Docs
Learn
Events
Simple way to copy last byte of a long to a new variable? — Parallax Forums
toggle menu
Categories
Discussions
Sign In
·
Register
Sign In
·
Register
Categories
Discussions
Sign In
·
Register
×
Home
›
Propeller 1
Simple way to copy last byte of a long to a new variable?
brianm734
Posts:
29
2012-07-25 16:57
edited 2012-07-27 08:39
in
Propeller 1
I am pretty new to SPIN. Is there a simple way to copy the last byte (LSB) of a long variable to a new byte sized variable?
Thanks
Comments
Phil Pilgrim (PhiPi)
Posts:
23,514
2012-07-25 17:02
edited 2012-07-25 17:02
byte_variable := byte[@long_variable]
... or just
byte_variable := long_variable (assuming byte_variable is declared as
byte
)
-Phil
brianm734
Posts:
29
2012-07-25 17:28
edited 2012-07-25 17:28
Great Phil, Thanks.
JonnyMac
Posts:
9,379
2012-07-27 08:25
edited 2012-07-27 08:25
You can get to any byte in a word or long using .byte[] notation as well.
bytevar := longvar.byte[0]
It's really not necessary for byte 0 (as Phil pointed out above), but useful for the others.
Beau Schwabe
Posts:
6,572
2012-07-27 08:39
edited 2012-07-27 08:39
There is also a way to do it without using any additional program overhead if you can define your long variable in the DAT section.
See this link:
http://forums.parallax.com/showthread.php?133583-VAR-Aliases...&p=1024313&viewfull=1#post1024313
Example using the Propeller demoboard or QuickStart LEDs:
http://forums.parallax.com/showthread.php?112970-Word-Sized-constant-in-Byte-array&p=808493&viewfull=1#post808493
Sign In
or
Register
to comment.
Comments
... or just
byte_variable := long_variable (assuming byte_variable is declared as byte)
-Phil
bytevar := longvar.byte[0]
It's really not necessary for byte 0 (as Phil pointed out above), but useful for the others.
See this link:
http://forums.parallax.com/showthread.php?133583-VAR-Aliases...&p=1024313&viewfull=1#post1024313
Example using the Propeller demoboard or QuickStart LEDs:
http://forums.parallax.com/showthread.php?112970-Word-Sized-constant-in-Byte-array&p=808493&viewfull=1#post808493