Shop OBEX P1 Docs P2 Docs Learn Events
How to update only a single bit from a byte. — Parallax Forums

How to update only a single bit from a byte.

AnubisbotAnubisbot Posts: 112
edited 2007-05-27 21:09 in Propeller 1
Hi, how di i update only a single bit from a byte.

I have a byte caled state0 and it beginning value is %0000_0001

then i want to update it to %00010_0001

then to %0101_0001 to change a bit without changing the other bits.

is there a way to say bit 5 from stat0 = 0


Thanx Anubisbot

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-05-27 17:56
    Use the logical bit operators (& | ^) and their assignment versions (&= |= ^=).

    Like: state0 |= %0010_0000

    Then: state0 ^= %0111_0000 or some equivalent
  • AnubisbotAnubisbot Posts: 112
    edited 2007-05-27 21:09
    Aha, like i thought, after looking once again to the operators in the manual.
    Thank you Mike...

    Anubisbot idea.gif
Sign In or Register to comment.