On 2/20/06, Pianoman <[EMAIL PROTECTED]> wrote:
> Hi, I need to know how can I see whether a certain bit of byte/word/dword is
> set:  or not:
> function like this would be appreciated:
> function isset(value: byte word or dword;bit:byte):boolean;
> for example when i pass the function parrameter a of type word and I want to
> see whether the bit 14 is set.

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;


--
Jonas Raoni Soares Silva
http://www.jsfromhell.com
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to