in reply to Boolean calculation incorrect values
About the only thing you are doing wrong is over complicating your sample code. Consider:
#!/usr/bin/perl use strict; use warnings; my $z = ~0; printf "%b 0x%x %d\n", $z, $z, $z;
Prints:
1111111111111111111111111111111111111111111111111111111111111111 0xff +ffffffffffffff -1
which is a 64 bit value with all bits set. That is the twos compliment representation of -1 and we've printed it as a binary value, a hex value and as a decimal value.
~ performs a bitwise compliment of the contents of a variable so the result is just what we expect. None of the subsequent operations you performed in your sample code changed the bit pattern.
|
|---|