Shop OBEX P1 Docs P2 Docs Learn Events
is there a command for reading a particular bit in a variable in memory?? — Parallax Forums

is there a command for reading a particular bit in a variable in memory??

laser-vectorlaser-vector Posts: 118
edited 2010-08-25 09:04 in Propeller 1
Hi all, this may be a simple question but:

lets say i have a variable named Status

Status is a long that equals %00000001_00000000_00000000_00001111

how would i do a bitwise lookup on bit 24 to see if its a 1 or 0??

thanks

Comments

  • HarleyHarley Posts: 997
    edited 2010-08-24 18:17
    @ laser-vector

    How about Bitwise decode '|<' if you are working in Spin?

    Status and |< 24
  • RaymanRayman Posts: 14,889
    edited 2010-08-24 18:27
    another option is to utilize the unimplemented B port registers...

    If you say outb:=status, then you can do:

    if outb[24] then...
  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-08-25 00:02
    bit := (variable >> bit_position) & 1
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-08-25 08:48
    Or, if you only care about zero vs. non-zero:

    if (variable & constant(1 << bit_position))
    .....

    -Phil
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2010-08-25 09:04
    Similar to Rayman's suggestion of using Port B, if you are not using one or both of the counters, you can use phsa, phsb, frqa, and frqb in the same way as the example he provided.
Sign In or Register to comment.