Need some help extracting bits from an int
bulkhead
Posts: 405
I am sending my BS2 a couple of command bits that indicate which sub routines should be run. I'd like to know how I can extract them from the byte and then run the corresponding sub routines. For example, the first bit is to turn on a LED, the second bit is to turn on a motor, the third bit to flash another LED. Is there a way I can just extract the single bit or do I need to have multiple IF statements, like IF (1) and IF (3) and IF(7) THEN turn_on_LED?
Comments
if VALUE AND 4 <> 0 THEN ...
extracts bit2
for bit0 to bit7 use values 1,2,4,8,16,32,64,128
But why not send a number to specify the subroutine.
Then you can use BRANCH.
regards peter
·