Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2017-03

tbits.NotBits

9 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Andrea Mauri

I didn't understand how TBits.NotBits works.
Consider the following code:

   b:= TBits.Create(NRECORDS);
   b.NotBits(b);

or more clear:

   b:= TBits.Create(NRECORDS);
   b.Clearall;
   b.NotBits(b);

I supposed that all bits of b will be 1. What I obtain is that all bits are 0.

fpc 3.0.0 win64

Am I missing something?
Thank you.
Andrea Mauri

Reply by email

Andrea Mauri
to Andrea Mauri

one more thing.
there is a method like clearall to set all bits to 1? clearall is much more faster then a simple iteration along all bits

Il 31/03/2017 14:07, Andrea Mauri ha scritto:

Show quoted text 21 lines
I didn't understand how TBits.NotBits works. Consider the following code: b:= TBits.Create(NRECORDS); b.NotBits(b); or more clear: b:= TBits.Create(NRECORDS); b.Clearall; b.NotBits(b); I supposed that all bits of b will be 1. What I obtain is that all bits are 0. fpc 3.0.0 win64 Am I missing something? Thank you. Andrea Mauri

Reply by email

Andrea Mauri
to Andrea Mauri

one last thing, using TBits it is possible to SetIndex in order to start from a predefined index when using FindNextBit and FindPrevBit Anyway it is possible to set the State only using FindFirstBit, so I cannot use FindNextBit only using SetIndex but I have to call also FindFirstBit.
Is it possible to introduce a SetState procedure?
Thanks again,
Andrea Mauri

Il 31/03/2017 14:10, Andrea Mauri ha scritto:

Show quoted text 26 lines
one more thing. there is a method like clearall to set all bits to 1? clearall is much more faster then a simple iteration along all bits Il 31/03/2017 14:07, Andrea Mauri ha scritto: > I didn't understand how TBits.NotBits works. > Consider the following code: > > > b:= TBits.Create(NRECORDS); > b.NotBits(b); > > or more clear: > > b:= TBits.Create(NRECORDS); > b.Clearall; > b.NotBits(b); > > I supposed that all bits of b will be 1. What I obtain is that all bits > are 0. > > fpc 3.0.0 win64 > > Am I missing something? > Thank you. > Andrea Mauri

Reply by email

Andrea Mauri
to Andrea Mauri: one more thing. there is a method like clearall to set all bits to 1? clearall is much…

any answer?
I asked in the wrong place?
where should I ask?

Il 31/03/2017 14:10, Andrea Mauri ha scritto:

Show quoted text 26 lines
one more thing. there is a method like clearall to set all bits to 1? clearall is much more faster then a simple iteration along all bits Il 31/03/2017 14:07, Andrea Mauri ha scritto: > I didn't understand how TBits.NotBits works. > Consider the following code: > > > b:= TBits.Create(NRECORDS); > b.NotBits(b); > > or more clear: > > b:= TBits.Create(NRECORDS); > b.Clearall; > b.NotBits(b); > > I supposed that all bits of b will be 1. What I obtain is that all bits > are 0. > > fpc 3.0.0 win64 > > Am I missing something? > Thank you. > Andrea Mauri

Reply by email

Michael Van Canneyt
to Andrea Mauri: any answer? I asked in the wrong place? where should I ask? Il 31/03/2017 14:10, Andrea…
Andrea Mauri wrote
any answer? I asked in the wrong place? where should I ask?

You asked in the right place. I just didn't notice your first mail.

I am not sure that what you did is supported.

b.notbits(b)

I am not sure that you can pass the same instance to b.

Can you test with 2 separate instances ?

Michael.

Show quoted text 32 lines
Il 31/03/2017 14:10, Andrea Mauri ha scritto: > one more thing. > there is a method like clearall to set all bits to 1? > clearall is much more faster then a simple iteration along all bits > > Il 31/03/2017 14:07, Andrea Mauri ha scritto: >> I didn't understand how TBits.NotBits works. >> Consider the following code: >> >> >> b:= TBits.Create(NRECORDS); >> b.NotBits(b); >> >> or more clear: >> >> b:= TBits.Create(NRECORDS); >> b.Clearall; >> b.NotBits(b); >> >> I supposed that all bits of b will be 1. What I obtain is that all bits >> are 0. >> >> fpc 3.0.0 win64 >> >> Am I missing something? >> Thank you. >> Andrea Mauri _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email

Andrea Mauri
to Mattias Gaertner: On Fri, 31 Mar 2017 14:07:09 +0200 AFAIK a.NotBits(b) means (a and not b): a b result 0 0…
Show quoted text 9 lines
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;

Reply by email

Mattias Gaertner
to Andrea Mauri
Show quoted text 7 lines
[...] procedure TBits.Setall; var loop : longint; begin for loop := 0 to FSize - 1 do FBits^[loop] := 1;
Should be
FBits^[loop] := not cardinal(0);
end;

Btw, it seems TBits misses an AssignBits(b: TBits).

And maybe an AssignNotBits(b: TBits)

Show quoted text 18 lines
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);

"Not" is a preserved word.

Show quoted text 12 lines
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;

For consistency with the other SomethingBits methods you must handle all bits, not just the start.

Mattias

Reply by email