Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Simple bit operations //Pascal functions (See related posts)

Get, Clear, Set and Enable bit operations for pascal.

function GetBit(const Value: DWord; const Bit: Byte): Boolean;
begin
  Result := (Value and (1 shl Bit)) <> 0;
end;

function ClearBit(const Value: DWord; const Bit: Byte): DWord;
begin
	Result := Value and not (1 shl Bit);
end;

function SetBit(const Value: DWord; const Bit: Byte): DWord;
begin
	Result := Value or (1 shl Bit);
end;

function EnableBit(const Value: DWord; const Bit: Byte; const TurnOn: Boolean): DWord;
begin
	Result := (Value or (1 shl Bit)) xor (Integer(not TurnOn) shl Bit);
end;

You need to create an account or log in to post comments to this site.


Click here to browse all 5140 code snippets

Related Posts