Shop OBEX P1 Docs P2 Docs Learn Events
test on specific bit in a variable — Parallax Forums

test on specific bit in a variable

Bobb FwedBobb Fwed Posts: 1,119
edited 2008-08-01 03:28 in BASIC Stamp
In PBASIC, is there any simple way to see what a specific bit is in a variable. SPIN uses "|<" syntax. Anything along those lines?

I have a nibble decimal variable, each bit represents a different setting. I have it all as one variable so I can output to the user a 9 rather than 1001 (I am limited to the number of displayed characters.

Comments

  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2008-07-31 20:33
    Nevermind...I found the .BIT# modifier. odd...but it does what I need
  • FORDFORD Posts: 221
    edited 2008-08-01 03:28
    another way is to do this...
    it works great for checking and also setting a bit in a byte, when you want to do it in a loop etc...

    thisbit var bit
    thatbyte var byte

    'TO·CHECK THE VALUE OF A BIT LOCATION IN A BYTE
    thisbit = thatbyte.bit0(n)············ 'where·n is the bit location in the byte ie: 0 - 7

    'TO·SET THE VALUE OF A BIT LOCATION IN A BYTE
    thatbyte.bit0(n) = thisbit············ 'where·n is the bit location in the byte ie: 0 - 7

    cheers,

    Chris, West Oz
Sign In or Register to comment.