// 位读
function GetBit(AValue: Byte; AIndex: 0..7): TBit;
const
Bool_Bit: array[False..True] of TBit = (0, 1);
begin
result := Bool_Bit[AValue and (1 shl AIndex)];
end;
// 位写
procedure SetBit(var AValue: Byte; AIndex: 0..7; ABit: TBit);
begin
if ABit = 0 then
AValue := AValue xor (1 shl AIndex)
else
AValue := AValue or (1 shl AIndex);
end;
Function SetValue(var aByte:Byte;pos:Byte;boo:Boolean):boolean;
type
Bits = (bit0,bit1,bit2,bit3,bit4,bit5,bit6,bit7) ;
TSetBits = set of Bits ;
PsetBits =^TSetBits ;
const
Const_Bits : array[0..7] of Bits =(bit0,bit1,bit2,bit3,bit4,bit5,bit6,bit7) ;
var
P :PsetBits ;
begin
Result := (pos>=0) and (pos<=7) ;
if not Result then Exit ;
P :=@aByte ;
if boo then
Include(P^,Const_Bits[pos])
else
Exclude(P^,Const_Bits[pos]);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
a : Byte ;
begin
a :=0;
SetValue(a,2,True) ;
caption := inttostr(a);
end;