posted 15 years ago
As I understand it, if you define a variable as a byte, then by using the | operator and the >>> operator, you can update an individual bit in the designated byte.
For example, in a program where b is defined as an array of bytes, you can do the following:
which will move a 1 in the first bit (bit 0) of byte 0.
if i do a it does show a value of 128, indicating that the 0 bit was indeed set.
However, I need to not only set various bits in random bytes, I have to go back and interrogate the individual bits later to see if they are set.
I think, in some way, you use the & operator, but not sure how.
My questions are:
1. Did I set the bit properly?
2. How do I determine later if the bit was saved? I can't simply check the value of the byte, because if the first and last bit was set to 1, then the value would be 129. I need to write some kind of loop where I check each bit and interrogate it.
thanks
bob