i need a little help with this code, i can't understand what it says:
Code: Select all
$second=251;
$tmp = ($second & 16) > 0 ? ( ($second & > 0 ? 1 : 2 ) : ( ($second & > 0 ? 0 : 2.5 )
// $tmp returns: 1Greetz,
Bomas
Moderator: General Moderators
Code: Select all
$second=251;
$tmp = ($second & 16) > 0 ? ( ($second & > 0 ? 1 : 2 ) : ( ($second & > 0 ? 0 : 2.5 )
// $tmp returns: 1Code: Select all
if (($second & 16) > 0) {
if (($second & > 0) {
$tmp = 1;
} else {
$tmp = 2;
}
} else {
if (($second & > 0) {
$tmp = 0;
} else {
$tmp = 2.5;
}
}Code: Select all
$second=251;
$tmp = ($second & 16) > 0? "a": "b");
//$tmp returns "a"ternaries are just a simple shorthand way of saying "if true, do this, else do this" all on one lineBomas wrote:i'm sorry, but i don't get the idea.
what does it do exactly, can you explain it for the first part of my codesnippet:what does the operator do? php.net says: "Bits that are set in both $a and $b are set."Code: Select all
$second=251; $tmp = ($second & 16) > 0? "a": "b"); //$tmp returns "a"
i don't get it.
and what does this line means: "Bitwise operators allow you to turn specific bits within an integer on or off".
thanx allready fr helping me out
Greetz,
Bomas
Code: Select all
$two = 251;
$three = 3;
$tmp = (($two & 16) > ?'a':'b';
$tmp2 = (($three & 16)> ?'a':'b';
echo "<br>two = $tmp<br>";
echo "three = $tmp2";
//outputs
//two = a
//three = bMaybe it'll help to see it written out this way. Compare the individual bits of both numbers to get the result. When the bits are different the result is a 0, when they are both 1 the result is a 1.what does the operator do? php.net says: "Bits that are set in both $a and $b are set."
i don't get it.
and what does this line means: "Bitwise operators allow you to turn specific bits within an integer on or off".
Code: Select all
binary decimal
1111 1011 251
& 0001 0000 & 16
------------ ----
0001 0000 16
1111 1011 251
& 0000 1000 & 8
------------ ----
0000 1000 8
1111 1011 251
& 0000 0100 & 4
------------ ----
0000 0000 0