Das Open-Control-Projekt - Die Alternative zur C-Control-I


Das Forum zur C-Control-1
Welche C-Control-Varianten existieren?
Übersicht - Suchen - Neueste 50 Beiträge - Neuer Beitrag - Login - Registrieren
INFO - FAQ - CC2-Forum - CCPro-Forum 

 Re: My programm didn't works Kategorie: Programmierung Basic (von Achim - 29.10.2006 1:22)
 Als Antwort auf My programm didn't works von Hans - 28.10.2006 23:28
Achim nutzt:  CC1-Station V1.1
> 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

Bisherige Antworten:

Re: My programm didn't works (von Hans - 29.10.2006 13:02)
    Re: My programm didn't works (von Achim - 29.10.2006 15:42)
        Re: My programm didn't works (von Hans - 29.10.2006 17:27)