Einzelnen Beitrag anzeigen

Benutzerbild von Aphton
Aphton

Registriert seit: 31. Mai 2009
1.198 Beiträge
 
Turbo Delphi für Win32
 
#36

AW: Bitoperationen

  Alt 25. Feb 2011, 20:02
Eigentlich setzt man doch ein Bit mit:
Code:
attribut:= attribut or $01;
Und entfernt es wieder mit:
Code:
attribut := attribut and not $02;
Oder?

Ich mache das wie folgt:
Button1:
Code:
attribut:= attribut or $01;
attribut := attribut and not $02;
Byte = 1

Button2:
Code:
attribut:= attribut or $02;
attribut := attribut and not $01;
Byte = 00000011
Ich verstehe nicht, warum du immernoch solche Fehler machst:
Code:
// "Eigentlich setzt man doch ein Bit mit:"
attribut:= attribut or $01;
// "Und entfernt es wieder mit:"
attribut := attribut and not $02;
Byte = 1
Im Grund hast du ja schon Recht mit dem Entfernen aber du entfernst nicht das gesetzte Bit, sondern das zweite Bit.
Sagen wir einmal, Attribut habe den Wert 0.

attribut:= attribut or $01 :
Code:
   00000000
or 00000001
-----------
   00000001
attribut := attribut and not $02;
Code:
not 2:
2     = 00000010
not 2 = 11111101

    00000001
and 11111101
------------
    00000001

Du erhälts also 1 binär, was 2^0 Dezimals entspricht,
das Erkennen beginnt, wenn der Erkennende vom zu Erkennenden Abstand nimmt
MfG
  Mit Zitat antworten Zitat