[fpc-devel] tbits.NotBits

Andrea Mauri andrea.mauri.75 at gmail.com
Thu Apr 13 11:28:20 CEST 2017


> AFAIK a.NotBits(b) means (a and not b):
>
> a b result
> 0 0 0
> 0 1 0
> 1 0 1
> 1 1 0
>
> Mattias

Thank you Mattias.
It works as you described.
Anyway, since ClearAll, AndBits, OrBits etc works iterating on
FBits : ^TBitArray;
they are much faster then the simple iteration along property
property Bits[Bit: longint]: Boolean read get write SetBit; default;

I think should be useful to have also at least two other methods 
directly implemented in tbits:
1. the opposite of ClearAll, something like SetAll that sets all bits to 
1, I think this s a typical operation on Bits;


procedure TBits.Setall;
var
    loop : longint;
begin
    for loop := 0 to FSize - 1 do
       FBits^[loop] := 1;
end;


2. a Not operator, something like a.NotBits; with no arguments that 
perform the not operation on the TBIts instance (a[i]:= not a[i]) or 
something that performs a not operation on the passed TBits, i.e. 
a.Not(b) that fills a in this way: a[i]:= not b[i];

procedure TBits.Notbits;
var
    n : longint;
    jj : cardinal;
    loop : longint;
begin
    for loop := 0 to FSize - 1 do
       FBits^[loop] := not FBits^[loop];
end;

or

procedure TBits.Not(bitset : TBits);
var
    n : longint;
    loop : longint;
begin
    if FSize < bitset.getFSize then
       n := FSize - 1
    else
       n := bitset.getFSize - 1;

    for loop := 0 to n do
       FBits^[loop] := not bitset.FBits^[loop];
end;




More information about the fpc-devel mailing list