INFO - FAQ - CC2-Forum - CCPro-Forum |
|
> I want to store 16 equation ( ON(1) or OFF(0) ) in 1 WORD > So that I can read it out later. > IF AdIn>140 THEN Var1=Var1 OR Temp ELSE Var1=Var1 NOR Temp If you have a word with one bit set to 1 and the others set to 0 like your temp-variable (which is called a "mask") then you set this particular bit in a different variable by or-ing it bitwise, that is correct. But you erase it not by nor-ing it, but rather by and-ing it bitwise with the one's complement of the mask. Example (four bits for better readability): Set the bit: Mask: 0010 Var: 0000 Or: 0010 Bit set, ok. Mask: 0010 Var: 1111 Or: 1111 Bit still set, ok Erase the bit: Mask: 0010 Var: 0000 Nor: 1101 Bit not set, other bits modified: incorrect! Mask: 0010 1's comp: 1101 Var: 0000 and: 0000 Bit still erased, correct Mask: 0010 1's comp 1101 Var: 1111 and: 1101 Bit erased, correct HTH Bye Achim |
Antwort schreiben |