Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 6 of 6 total
Thread XOR operations confused with OR
Wed, Feb 10 2021 12:20 PMPermanent Link

Jose Verger

Cybernav

Avatar

Hello,

I made the upgrade from EWB2 to EWB3, and I just found that all places where I wrote something like:   A xor $FF
result in $FF, regardless of the value of A, so, it means that the compiler is doing an OR operation instead of a XOR.

Regards
Wed, Feb 10 2021 1:37 PMPermanent Link

Raul

Globestar Systems

Team Elevate Team Elevate

On 2/10/2021 12:20 PM, Cybernav wrote:
> I made the upgrade from EWB2 to EWB3, and I just found that all places where I wrote something like:   A xor $FF
> result in $FF, regardless of the value of A, so, it means that the compiler is doing an OR operation instead of a XOR.

Can you supply a sample values ?

I ran this here (i,j,b are integer) :

  b := $FF;
  for i := 0 to  255 do
  begin
   j := i XOR b;
   log(inttostr(j));
  end;

and got

255
254
...
1
0

which looks ok

Raul
Wed, Feb 10 2021 2:05 PMPermanent Link

Jose Verger

Cybernav

Avatar

Hello Raul, I wrote this small program to display calculations:

unit HttpU;

interface

uses WebCore, WebUI, WebHTTP, WebForms, WebCtrls, WebBrwsr, WebCtnrs;
type
    TForm1 = class(TDialog)
         procedure Form1Show(Sender: TObject);
    private
         { Private declarations }
    public
         { Public declarations }
    end;
var Form1: TForm1;

implementation

const Num=$80;

procedure TForm1.Form1Show(Sender: TObject);
begin
logoutput('A'+IntToStr(Num xor $FF));
logoutput('B'+IntToStr($80 xor $FF));
end;

end.

And in the output window bellow it displays the following:

[Internal] Log output: A255
[Internal] Log output: B255
Wed, Feb 10 2021 3:37 PMPermanent Link

Raul

Globestar Systems

Team Elevate Team Elevate

On 2/10/2021 2:05 PM, JoseV wrote:
> Hello Raul, I wrote this small program to display calculations:

Thanks

> const Num=$80;
>
> procedure TForm1.Form1Show(Sender: TObject);
> begin
> logoutput('A'+IntToStr(Num xor $FF));
> logoutput('B'+IntToStr($80 xor $FF));
> end;
>

Looks to be a but with type interference or casting or such

This works OK and returns B127

var
  b:integer;
begin
  b := Num;
  logoutput( ('B'+IntToStr(b xor $FF)));
end;


Raul
Wed, Feb 10 2021 4:03 PMPermanent Link

erickengelke

Raul wrote:

On 2/10/2021 2:05 PM, JoseV wrote:
> Hello Raul, I wrote this small program to display calculations:


>This works OK and returns B127

If you look at the generated javascript, the Y XOR $FF is evaluated at compile time, not at runtime if Y is a constant.

Declaring Y as a variable seems to fix it.  

Yeah, a small bug.

Erick
EWB Programming Books and Component Library
http://www.erickengelke.com
Thu, Feb 11 2021 11:17 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Erick,

<< If you look at the generated javascript, the Y XOR $FF is evaluated at compile time, not at runtime if Y is a constant. >>

Yep, that's the issue - the constant folding in the compiler has an error in how it is evaluating xor operations.  The workaround is as-described.

A fix will be in build 2 shortly.

Thanks,

Tim Young
Elevate Software
www.elevatesoft.com
Image