Jump to content

[Delphi] Set/Reset specific bit

- - - - -

  • Please log in to reply
No replies to this topic

#1
LuthfiHakim

LuthfiHakim

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 763 posts
The following code sets the bit specified by AIndex of an integer value. Set means making the bit into 1.

procedure SetBit(var AValue: Integer; const AIndex: Integer);

begin

  AValue := AValue or (1 shl AIndex);

end;


The following code resets the bit specified by AIndex of an integer value. Reset means making the bit into 0.

procedure ResetBit(var AValue: Integer; const AIndex: Integer);

begin

  AValue := AValue and (not (1 shl AIndex));

end;






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users