![]() |
AW: Bitoperationen
Hallo,
ich verstehe, was ihr meint. Auch wenn es vielleicht unsinnig und sinnfrei ist, mach ich erstmal weiter. Eigentlich setzt man doch ein Bit mit:
Code:
Und entfernt es wieder mit:
attribut:= attribut or $01;
Code:
Oder?
attribut := attribut and not $01;
Ich mache das wie folgt: Button1:
Code:
Byte = 1
attribut:= attribut or $01;
attribut := attribut and not $02; Button2:
Code:
Byte = 00000011
attribut:= attribut or $02;
attribut := attribut and not $01; Es müsste doch 00000010 rauskommen!? Fg Dunkelbunt |
AW: Bitoperationen
Du meinst 10 binär? Ja, das sollte eigentlich so sein. Lässt Du Dir auch zum richtigen Zeitpunkt den aktuellen Wert ausgeben?
|
AW: Bitoperationen
Ja ich meine binär.
Ich denke der Zeitpunkt stimmt. Immer wenn ich mit den Pfeiltasten die PositionSpalte bzw PositionZeile bewege wird der Ihalt des Bytes angezeigt, sprich Zeichen und dazugehöriger binärer Wert ... Edit: Ich kenne jetzt den Fehler. Es lag daran, dass zwar die eigentlich Berechnung stimmte, sie aber für das falsche Feld ausgeführt wird. |
AW: Bitoperationen
Ich hab mal schnell ein Beispielprojekt erstellt, da stimmt alles.
Delphi-Quellcode:
procedure TForm5.Button1Click(Sender: TObject);
function ByteToString(b: Byte): string; const BitChars: array [Boolean] of Char = ('0', '1'); var Bit, Posi: Byte; begin SetLength(Result, SizeOf(b) shl 3); Bit := 1; Posi := Length(Result); while Posi > 0 do begin Result[Posi] := BitChars[b and Bit = Bit]; Bit := Bit shl 1; dec(Posi); end; end; var attribut: Byte; begin attribut := 0; attribut := attribut or $01; attribut := attribut and not $02; ShowMessage(ByteToString(attribut)); attribut := attribut or $02; attribut := attribut and not $01; ShowMessage(ByteToString(attribut)); end; |
AW: Bitoperationen
Danke für das Beispiel.
Dein ByteToStr ist echt gut, ich hatte es ein wenig anderst gemacht, aber das ist nicht so wichtig. An dieser Stelle funktioniert alles was funktionieren soll, denke ich. Ich muss jetzt nur noch interne Probleme lösen... Danke auch an die Andere hilfsbereiten DP-Member, Dunkelbunt |
AW: Bitoperationen
Zitat:
Code:
Im Grund hast du ja schon Recht mit dem Entfernen aber du entfernst nicht das gesetzte Bit, sondern das zweite Bit.
// "Eigentlich setzt man doch ein Bit mit:"
attribut:= attribut or $01; // "Und entfernt es wieder mit:" attribut := attribut and not $02; Byte = 1 Sagen wir einmal, Attribut habe den Wert 0. attribut:= attribut or $01 :
Code:
attribut := attribut and not $02;
00000000
or 00000001 ----------- 00000001
Code:
not 2:
2 = 00000010 not 2 = 11111101 00000001 and 11111101 ------------ 00000001 Du erhälts also 1 binär, was 2^0 Dezimals entspricht, |
AW: Bitoperationen
Hallo,
Zitat:
FG Dunkelbunt |
Alle Zeitangaben in WEZ +1. Es ist jetzt 12:31 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz