var

i: integer;

m: Multi_Int_XV;

begin

writeln('xor on integer = ok');

i := 1;

writeln(binstr(i, 32), ' = ', i);

i := i xor (1 shl 31);

writeln(binstr(i, 32), ' = ', i);

writeln;

writeln('xor on integer then casted to Multi_Int_XV = ok');

i := 1;

m := i;

writeln(binstr(integer(m), 32), ' = ', string(m));

i := i xor (1 shl 31);

m := i;

writeln(binstr(integer(m), 32), ' = ', string(m));

writeln;

writeln('xor on Multi_Int_XV = overflow on cast to integer');

m := 1;

writeln(binstr(integer(m), 32), ' = ', string(m));

m := m xor (1 shl 31);

//writeln(binstr(integer(m), 32), ' = ', string(m)); // integer(m) = overflow

// because of overflow, lets cast it to int64

writeln(binstr(int64(m), 32), ' = ', string(m)); // high 32 bits are 0s

writeln;

// is the value the same as integer?

writeln('value correct? ', int64(m) = i, ', ', int64(m), ' vs ', i);

writeln('bits the same? ', binstr(i, 64) = binstr(int64(m), 64));

writeln('i bits = ', binstr(i, 64));

writeln('m bits = ', binstr(int64(m), 64));

writeln;

writeln('------------------------');

writeln;

writeln('negative value, test on integer');

i := -1;

i := i xor (1 shl 31);

writeln('i = ', i, ', bits = ', binstr(i, 32));

writeln('negative value, test on Multi_Int_XV');

m := -1;

//m := m xor (1 shl 31); // failed: Raise EInterror.create('Bitwise operation on negative value');