Unary NOT/Integersize of the architecture
- by sid_com
From "Mastering Perl/Chapter 16/Bit Operators/Unary NOT,~":
The unary NOT operator (sometimes called the complement operator), ~, returns the bitwise negation, or 1's complement, of the value, based on integer size of the architecture
Why does the following script output two different values?
#!/usr/local/bin/perl
use warnings;
use 5.012;
use Config;
my $int_size = $Config{intsize} * 8;
my $value = 0b1111_1111;
my $complement = ~ $value;
say length sprintf "%${int_size}b", $value;
say length sprintf "%${int_size}b", $complement;
Output:
32
64