Questions about this topic? Sign up to ask in the talk tab.
Difference between revisions of "Perl/Basics/Boolean Logic/Bitwise Manipulations"
From NetSec
Chantal21I (Talk | contribs) |
Chantal21I (Talk | contribs) |
||
Line 1: | Line 1: | ||
Perl's bitwise manipulations cover the syntax for performing '''[[Bitwise Math|bitwise math]]''' on variables. | Perl's bitwise manipulations cover the syntax for performing '''[[Bitwise Math|bitwise math]]''' on variables. | ||
+ | |||
+ | ====[[Bitwise_Math#AND|AND]]==== | ||
+ | {{:Perl/Basics/Boolean Logic/Bitwise_Manipulations/AND}} | ||
+ | |||
+ | ====[[Bitwise_Math#NOT|NOT]]==== | ||
+ | {{:Perl/Basics/Boolean Logic/Bitwise_Manipulations/NOT}} | ||
+ | |||
+ | ====[[Bitwise_Math#OR|OR]]==== | ||
+ | {{:Perl/Basics/Boolean Logic/Bitwise_Manipulations/OR}} | ||
+ | |||
+ | ====[[Bitwise_Math#XOR|XOR]]==== | ||
+ | {{:Perl/Basics/Boolean Logic/Bitwise_Manipulations/XOR}} | ||
+ | |||
+ | ====[[Bitwise_Math#Logical_Shifts|Bit Shifting]]==== | ||
+ | {{:Perl/Basics/Boolean Logic/Bitwise_Manipulations/Bit_Shifting}} | ||
+ | |||
+ | ====[[Bitwise_Math#Circular_Shift_or_Bit_Rotation|Bit Rotation]]==== | ||
+ | {{:Perl/Basics/Boolean Logic/Bitwise_Manipulations/Bit_Rotation}} |
Latest revision as of 01:31, 19 July 2012
Perl's bitwise manipulations cover the syntax for performing bitwise math on variables.
Contents
AND
- & - The AND operator.
my $num = 10; $num = $num & 25; print $num . "\n"; |
NOT
- ~ - The NOT operator
my $num = 10; $num = ~$num; print $num . "\n"; |
OR
- | - The OR operator
my $num = 10; $num = $num | 25; print $num . "\n"; |
XOR
- ^ - The xor (exclusive or) operator
my $num = 10; $num = $num ^ 25; print $num . "\n"; |
Bit Shifting
- << - The shift left operator
- >> - The shift right operator
<syntaxhighlight lang="perl">my $num = 10; $num = $num << 2; #Shift left two bits $num = $num >> 2; #Shift right two bits print $num . "\n"; </syntaxhighlight> |
Bit Rotation
Perl bit rotation requires the Bit::ShiftReg package from CPAN. More information available there.