for some reason long to explain I want to do the following bitwise operations in perl: (let's assume that 1 means true and 0 means false)
$var1="11000001";
$var2="10000101";
$y=$var1 & $var2; #bitwise and
$o=$var1 | $var2; #bitwise or
print "var1 & var2: $y\n";
print "var1 | var2: $o\n";
Then, I get the same output both in windows perl and in Linux perl:
var1 & var2: 10000001 (which is what I wished)
var1 | var2: 11000101 (which is what I wished)
BUT if I do:
$xox=$var1^$var2; # bitwise xor
print "var1 ^ var2: $xox\n";
then the output in windows is:
var1 ^ var2: ☺ ☺
while in linux is:
var1 ^ var2:
Given that the & and | operators seem to work as 'expected', I was also expecting to get something like:
$var1="11000001";
$var2="10000101";
$xox=$var1^$var2; # bitwise xor
print "var1 ^ var2 --> $xox\n";
var1 ^ var2 --> 01000100
for the ^ operator.
But, as shown above, this is not the case for both windows and linux, although at least the windows output for xor is useful for my purposes, but not the linux output.
Can anyone explain why the '&' or '|' operators seem to work but not the '^' (XOR) operator? And why is there that difference between linux and windows? Thanks
NOTE: specifying int($var1) ^ int($var2) does not result in a desirable result (for me; i.e. to get as output 01000100)