Need to invert a bit in a byte
Jonmar
Posts: 9
Howdy all,
I need to Invert a single "bit" in a Byte without disturbing any of the other bits.
Upon entering the needed subroutine, I will know which bit that I need to affect.
Also I need to do this with a minimal amount of code.
I am using a BS2e module.
Any suggestions would be appreciated.
Thanks in advance
Jon
I need to Invert a single "bit" in a Byte without disturbing any of the other bits.
Upon entering the needed subroutine, I will know which bit that I need to affect.
Also I need to do this with a minimal amount of code.
I am using a BS2e module.
Any suggestions would be appreciated.
Thanks in advance
Jon
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
For example, if whichBit=5, then DCD whichBit will equal %00100000 with the fifth bit set, and then the XOR, ^ in PBASIC causes that one bit to flip.
Another way, using the fact that bits in a byte can be array-addressed counting up from bit 0:
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Post Edited (Tracy Allen) : 8/29/2008 4:44:37 AM GMT
Might be same bit, but usually a different bit each time through sub routine.
Jon