Shop OBEX P1 Docs P2 Docs Learn Events
Need some help extracting bits from an int — Parallax Forums

Need some help extracting bits from an int

bulkheadbulkhead Posts: 405
edited 2006-08-08 21:31 in BASIC Stamp
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

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-08-08 21:31
    AND with value for specific bit,
    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
    ·
Sign In or Register to comment.