Public Domain Photos - Free for commercial redistribution and alteration (All photo from http://public-photo.net/ is 100% free for use)
Home » Bookmarks, pHp

PHP Bitwise Operators

443 views 2 Comments[ Retwitt ]
OperatorDescriptionResult
$a & $bAndBits that are set in both $a
and $b are set.
$a | $bOr (inclusive or)Bits that are set in either $a
or $b are set.
$a ^ $bXor (exclusive or)Bits that are set in $a
or $b but not both are set.
$a << $bShift leftShift the bits of $a
$b steps to the left (each step means
“multiply by two”)
$a >> $bShift rightShift the bits of $a
$b steps to the right (each step means
“divide by two”)
~ $aNotBits that are set in $a
are not set, and vice versa.

php logoBitwise operators allow evaluation and manipulation of specific bits within an integer. If both the left-hand and right-hand parameters are strings, the bitwise operator will operate on the characters’ ASCII values.

Warning: Don’t right shift for more than 32 bits on 32 bits systems. Don’t left shift in case it results to number longer than 32 bit. Use functions from the gmp extension ( gmp_and(), gmp_or(), gmp_xor(), gmp_testbit(), gmp_clrbit() ) for bitwise manipulation on numbers beyond PHP_INT_MAX.

[ Short URL ... ]

2 Comments »

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.