![]() |
AW: Bitoperationen
Hallo,
:-D Ich muss mich aber doch nochmal melden. Ich habe mir nun Bits angelegt um die Farben von Text zu steuern, zum testen. Aber es funktioniert noch nicht.... Es sieht bis jetzt so aus:
Delphi-Quellcode:
Ich hoffe das reicht um mein Problem nachzuvollziehen.
type
TBuchstabe = record Zeichen : char; Attribut : byte; end; ... const flschwarz = 1; //Geändert! flblau = 2; flrot = 4; flgruen = 8; flgrau = 16; ... var buchstabe : array of array of TBuchstabe; ... procedure TForm1.schwarzClick(Sender: TObject); begin buchstabe[PositionSpalte,PositionZeile].attribut:= $FF shr 7 shl 7; //1. Bit setzen //Andere Farbbits ausschalten if buchstabe[PositionSpalte,PositionZeile].attribut and flblau > 0 then buchstabe[PositionSpalte,PositionZeile].attribut := buchstabe[PositionSpalte,PositionZeile].attribut and not flblau; end; ... procedure TForm1.blauClick(Sender: TObject); begin buchstabe[PositionSpalte,PositionZeile].attribut:= $FF shr 7 shl 6; //2. Bit setzen //Andere Farbbits ausschalten if buchstabe[PositionSpalte,PositionZeile].attribut and flgruen > 0 then buchstabe[PositionSpalte,PositionZeile].attribut := buchstabe[PositionSpalte,PositionZeile].attribut and not flgruen; if buchstabe[PositionSpalte,PositionZeile].attribut and flrot > 0 then buchstabe[PositionSpalte,PositionZeile].attribut := buchstabe[PositionSpalte,PositionZeile].attribut and not flrot; if buchstabe[PositionSpalte,PositionZeile].attribut and flgrau > 0 then buchstabe[PositionSpalte,PositionZeile].attribut := buchstabe[PositionSpalte,PositionZeile].attribut and not flgrau; end; ... procedure buchstaben; var i,n : integer; begin for i := 1 to AnzahlSpalten do for n := 1 to AnzahlZeilen do begin // Bit Abfragen if (buchstabe[i,n].Attribut and flschwarz > 0) then Form1.Canvas.Font.Color:=clblack; if (buchstabe[i,n].Attribut and flblau > 0) then Form1.Canvas.Font.Color:=clblue; if (buchstabe[i,n].Attribut and flrot > 0) then Form1.Canvas.Font.Color:=clred; if (buchstabe[i,n].Attribut and flgruen > 0) then Form1.Canvas.Font.Color:=clgreen; if (buchstabe[i,n].Attribut and flgrau > 0) then Form1.Canvas.Font.Color:=clgray; Form1.Canvas.TextOut(spalten[i],zeilen[n],buchstabe[i,n].zeichen); end; end; FG Dunkelbunt |
AW: Bitoperationen
Zitat:
|
AW: Bitoperationen
Ähm, ...
Wie kann ich das denn sonst machen ich hatte mir gedacht: $FF = 11111111 1111 1111 shr 7 = 0000 0001 shl 5 = 0010 000 Dann habe ich an der 3. Stelle ein Bit ... FG Dunkelbunt |
AW: Bitoperationen
Delphi-Quellcode:
[edit] Mir fällt gerade auf, dass Dein $16 nicht richtig ist, das muss entweder einfach 16 oder $10 heißen. [/edit]
Attribut := $20; //oder die entsprechende Konstante
|
AW: Bitoperationen
Es funktioniert immernoch nicht :cry:
Delphi-Quellcode:
Was mache ich falsch....
procedure TForm1.blauClick(Sender: TObject);
begin buchstabe[PositionSpalte,PositionZeile].attribut:= $20; //2. Bit setzen end; procedure TForm1.schwarzClick(Sender: TObject); begin buchstabe[PositionSpalte,PositionZeile].attribut:= $1; //1. Bit setzen end; procedure buchstaben; // Vorbereitung für das schnelle anzeigen von Buchstaben var lauf,i,n : integer; begin for i := 1 to AnzahlSpalten do for n := 1 to AnzahlZeilen do begin // Bit Abfragen if (buchstabe[i,n].Attribut and flschwarz > 0) then Form1.Canvas.Font.Color:=clblack; if (buchstabe[i,n].Attribut and flblau > 0) then Form1.Canvas.Font.Color:=clblue; if (buchstabe[i,n].Attribut and flrot > 0) then Form1.Canvas.Font.Color:=clred; if (buchstabe[i,n].Attribut and flgruen > 0) then Form1.Canvas.Font.Color:=clgreen; if (buchstabe[i,n].Attribut and flgrau > 0) then Form1.Canvas.Font.Color:=clgray; Form1.Canvas.TextOut(spalten[i],zeilen[n],buchstabe[i,n].zeichen); end; end; const flschwarz = $1; flblau = $20; flrot = $36; flgruen = 8; flgrau = 16; TBuchstabe = record Zeichen : char; Attribut : byte; end; buchstabe : array of array of TBuchstabe; ... |
AW: Bitoperationen
Zitat:
Per $ gibt man in Delphi anstatt Dezimalwerte Hexwerte ein. Diese haben die Basis 16, anstatt 10. $10 (Hex) = 16 (Dez). $20 (Hex) = 32 (Dez). Und jetzt kommts... DAS - HAT - NICHTS - MIT - BITS - ZU - TUN |
AW: Bitoperationen
Zitat:
|
AW: Bitoperationen
Ich wusste, dass diese Antwort kommt.
Relativ gesehen nicht. Also er hat sich ja dabei gedacht, dass das einzelne Bits präsentiert. Nochmal zum Problem:
Code:
Diese Folge kann man auch als eine 2er Potenz anschreiben:
Bit 1 = 00000001 = 1 (Dezimal) = $01 (Hexadezimal)
Bit 2 = 00000010 = 2 (Dezimal) = $02 (Hexadezimal) Bit 3 = 00000100 = 4 (Dezimal) = $04 (Hexadezimal) Bit 4 = 00001000 = 8 (Dezimal) = $08 (Hexadezimal) Bit 5 = 00010000 = 16 (Dezimal) = $10 (Hexadezimal) Bit 6 = 00100000 = 32 (Dezimal) = $20 (Hexadezimal) Bit 7 = 01000000 = 64 (Dezimal) = $40 (Hexadezimal) Bit 8 = 10000000 = 128 (Dezimal) = $80 (Hexadezimal) 2^0, 2^1, 2^2, 2^3, 2^4, 2^5, 2^6, 2^7, ... Edit: Ach übrigens, warum verwendest du nicht einfach mein kleines Record um die Einzelnen Bits zu setzen?
Delphi-Quellcode:
// Ersetze folgendes
type TBuchstabe = record Zeichen : char; Attribut : byte; end; // mit das hier: type TBuchstabe = record Zeichen : char; Attribut : TBitByte; end; |
AW: Bitoperationen
Gibt es einen bestimmten Grund dafür, dass man nicht einfach TColor nimmt?
|
AW: Bitoperationen
Zitat:
Wieso kommst du jetzt auf TColor? So viele Bits braucht er doch gar nicht .... |
Alle Zeitangaben in WEZ +1. Es ist jetzt 06:43 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