Hello all,
I'm just starting with PHP.
I've got a source code of an online mass multyplayer web game.
I'm studying te php code when I came along this:
if (mysql_num_rows($result) == 1) {
$myrow = mysql_fetch_row($result);
if (($myrow[1] & 0x0F) == 4 )
So what I don't understand were stands the 0x0F for ?
And if I read it the right way this tells me that if mysql_num_rows($rsult) = 1 the $myrow = 1 right ? or ALL wrong ?
If that is so then in the next line $myrow[1] = 1 and after that I'm clueless what does the "&" mean and the 0x0F ???
Hope you can help me
thnx
pMzQ,[/b]
Question about a php variable ?
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
0x0F is the hex code for 15 (decimal)
$myrow[1] is being compared on the bit level if it has commonality with the number 15 or 00001111 in bits. The results of this bitmask are compared against 4 or 00000100 in bits. Basically, it's assessing if the lower nibble of the second element from $myrow is 4.
$myrow[1] is being compared on the bit level if it has commonality with the number 15 or 00001111 in bits. The results of this bitmask are compared against 4 or 00000100 in bits. Basically, it's assessing if the lower nibble of the second element from $myrow is 4.
it's setting $myrow to the resultant record if there is only one row in the result set. i.e. if mysql_num_rows() returns 1, set $myrow to the first (and only) record in the result set.And if I read it the right way this tells me that if mysql_num_rows($rsult) = 1 the $myrow = 1 right ? or ALL wrong ?
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
it actually can be true. The & operator does a bitmask. The bits matching between the two variables are returned. Here's an example
Code: Select all
00001111 = 15 (0x0F)
& 00000100 = 4 (0x04)
----------
00000100 = 4 (0x04)
01010101 = 85 (0x55)
& 00001111 = 15 (0x0F)
----------
00000101 = 5 (0x05) != 4- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
As feyd told you, all characters within 0-9, A-F which starts with 0x as prefix are hexadecimals.pmzq wrote:thnx for your respons.
So the statement
if (($myrow[1] & 0x0F) == 4 )
Isn't true then? right because 0x0F is 15 so no 4 and means this statement isn't true ?
thnx
pMzQ,
The if condition might yield a Boolean TRUE if $myrow[1] when it makes an AND operation against 0x0F (15) return 0x04(4). It all depends on the value taken by the $myrow[1]
Code: Select all
for simplicity, i am considering values to be only of four digits or just one hexadecimal character
1111- 15
0111 - 7
0101 - 5
0100 - 4
AND
0100 - 4
WILL RETURN 0100