Bitwise Operators

Operator Meaning
& and
| or
^ excl. or
<< shift left
>> shift right

$r1 = 0xfa;
$r2 = 0xfb;
$r3 = 0xfc;
#
# combine 3 bytes to a 24 bit word
#
$r = $r1 | $r2 << 8 | $r3 << 16 ;
#
# r: 0xfcfbfa
#

#
# combine the complement of 3 bytes to a 24 bit word
#
$r = (~$r1 & 0xff) | 
    (~$r2 << 8  & 0xff00) | 
    (~$r3 << 16  & 0xff0000) + 1;
#
# r: 0x30405
#