Hi folks - I hope thats a suitable subject - not totally sure how to describe what I'm aiming for - but here goes...
I've got a little application I'm working on where a logic variable changes state when a button is pressed. I can do this quite simply with:
new_state=1-old_state
Now, I wanted to do this with multiple buttons and I figured having multiple variables was a bit wasteful, so I could do it all by changing the state of individual bits in a byte.
Here's the tricky part - I can read individual bits by doing a bitwise and (x&y) with 1,2,4 etc. But I can't figure out how to write the new values back into correct position of the byte. I don't think adding individual values of 1,2,4 etc will work as the maths could soon get messy...
Any ideas? (Does that even make sense?)
Thanks