How to use bitwise XOR in Pascal

1 Answer

0 votes
(*
 
X Y | X ^ Y
0 0 |   0
0 1 |   1
1 0 |   1
1 1 |   0
 
*)

program XORBits;

var
  x, y: Integer;
begin
  x := 5; y := 5;
  Writeln(BinStr(x, 8));
  WriteLn('^');
  Writeln(BinStr(y, 8));
  WriteLn('=');
  Writeln(BinStr(x xor y, 8));
  WriteLn(#10#10);

  x := 7; y := 0;
  Writeln(BinStr(x, 8));
  WriteLn('^');
  Writeln(BinStr(y, 8));
  WriteLn('=');
  Writeln(BinStr(x xor y, 8));
  WriteLn(#10#10);

  x := 0; y := 6;
  Writeln(BinStr(x, 8));
  WriteLn('^');
  Writeln(BinStr(y, 8));
  WriteLn('=');
  Writeln(BinStr(x xor y, 8));
  WriteLn(#10#10);

  x := 0; y := 0;
  Writeln(BinStr(x, 8));
  WriteLn('^');
  Writeln(BinStr(y, 8));
  WriteLn('=');
  Writeln(BinStr(x xor y, 8));
  WriteLn(#10#10);
end.


   
(*
run:
  
00000101
^
00000101
=
00000000



00000111
^
00000000
=
00000111



00000000
^
00000110
=
00000110



00000000
^
00000000
=
00000000
  
*)

 



answered Jul 11 by avibootz
...