Reputation: 830
I am beginning to think I am losing my mind. I have Delphi 10.4.2 with latest patch. I cannot get this Boolean to work
procedure TForm1.Button1Click(Sender: TObject);
var j,k, m: integer;
begin
j := 1; m := 14;
k := j And m;
end;
I am happy to be proved wrong but in my books 1 logical and 14 should result in 1 but it is reporting as 0.
Upvotes: 0
Views: 205
Reputation: 2293
In this context, you are not using And
as a Boolean operator, as the arguments are not Booleans.
Instead, it's being used as a bitwise operator.
1 is, well, 1, or 00000001 in binary.
14 is $0e, or 00001110 in binary.
When you do a bitwis and
of $0e and $1, you will get 0 - which is correct.
Upvotes: 2
Reputation: 311
And
in this case is a bitwise operator.
14 is 1110 in binary.
1 is 0001 in binary.
1110 & 0001 = 0
Upvotes: 1