AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Programmieren allgemein Zugriff auf einzelne bits einer Variable
Thema durchsuchen
Ansicht
Themen-Optionen

Zugriff auf einzelne bits einer Variable

Ein Thema von earlyperl · begonnen am 15. Apr 2008 · letzter Beitrag vom 15. Apr 2008
 
Benutzerbild von nicodex
nicodex

Registriert seit: 2. Jan 2008
Ort: Darmstadt
286 Beiträge
 
Delphi 2007 Professional
 
#3

Re: Zugriff auf einzelne bits einer Variable

  Alt 15. Apr 2008, 10:45
Was genau willst du machen?

ps: Es gibt die Möglichkeit die Bits über ein Set abzubilden, sie über Operatoren zu lesen/manipulieren, oder die Klasse TBits zu verwenden...
edit: "(Variable and 8) = 8" ist langsamer als "(Variable and 8) <> 0".

Delphi-Quellcode:
type
  PByteBit = ^TByteBit;
  TByteBit = (bBit0, bBit1, bBit2, bBit3, bBit4, bBit5, bBit6, bBit7);
  PByteBits = ^TByteBits;
  TByteBits = set of TByteBit;

function TestBit(ABits: TByteBits; ABit: TByteBit): Boolean;
{$IFDEF SUPPORTS_INLINE} inline; {$ENDIF}
begin
  Result := ABit in ABits;
end;

procedure Foo();
var
  Bar: Byte;
begin
  Bar := 42;
  if TestBit(TByteBits(Bar), bBit1) then
    ShowMessage('Hello, World!');
end;
Nico Bendlin
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 20:25 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