Jump to content

**solved**What are these wierd numbers and what do they mean ?


pmzq

Recommended Posts

Hy all,

I've got a code like this:

$q ="UPDATE planet SET has_politics=$myrow[has_politics] & 0xfe ".
"WHERE id='$Planetid'";
$result = mysql_query ($q, $db);

IT tells the "has_politics" to become 0xfe but what does this mean is it some sort of haxdecimal code for a certain number ?

In a earlier part of the code the "has_politics" is set like the following:

$q = "UPDATE planet set has_politics = has_politics | 1 ".
"WHERE x='$myrow[x]' AND y='$myrow[y]' AND id!='$Planetid'";
$result = mysql_query ($q, $db);

So I think the code above sets the "has_politics" to 1 and 0xfe code sets it to 0 again or something ?

Can anyone tell em what that part of code does?

thnx again
pMzQ,
Link to comment
Share on other sites

0xFE is a hexidecimal numeric character code... I think

Some info on this can be found [a href=\"http://www.delorie.com/gnu/docs/fontutils/fontu_16.html\" target=\"_blank\"]>> HERE <<[/a] and [a href=\"http://www.w3.org/International/questions/qa-escapes\" target=\"_blank\"]>> HERE <<[/a]
Link to comment
Share on other sites

thnx for these answers so far :)

But do you know if I can just replace them with normal numbers isntead of those heximal just put the real number in there so i don't have to look up all the time what it is meaning.. ?
Link to comment
Share on other sites

Ok I understand but still I don't know what to replace 0xfe with how do i calculate the decimal for this hexadecimal number ? I can calculate the binary of this which is i think 1111 1110 meaning f and e.

But how do i translate this to a real number ?

ok i think 0xfe means decimal 254.

But then I'm still confused because when I look in my mysql database when this code is run:

$q = "UPDATE planet set has_politics = has_politics | 1 ".
"WHERE x='$myrow[x]' AND y='$myrow[y]' AND id!='$Planetid'";
$result = mysql_query ($q, $db);

The "has_politics" row shows that it's value = 1 sofar i understand but then after this code is run:

$q ="UPDATE planet SET has_politics=$myrow[has_politics] & 0xfe ".
"WHERE id='$Planetid'";
$result = mysql_query ($q, $db);
$myrow["has_politics"] = $myrow["has_politics"] & 0xfe;

then the value of "has_politics" is set back to 0 so 0xfe is meaning something like -1 because the value was 1 and after the code is run it is 0. But i just calculated that fe means 254 :| ???????
Link to comment
Share on other sites

the mysql UPDATE doesnt perform a mathematical calculation, it just changes the value of the field to whatever you specify.

If it is resetting the field to 0 when you run the 0xFE code on it, then 0xFE in terms of your script is equal to 0.
Ignore the hex code translation of it... 254 is what FE is in hex. This means that if you were to convert the hex color code #FEFEFE from hex to RGB value, it would translate to R:254 G:254 B:254.

In otherwords... it would be a very pale grey... almost white.

But ignore that... in your case its setting the table entry to 0, so 0xFE=0.
Link to comment
Share on other sites

Ok I think I'm getting there,

I think because "has_politics" is set to 1 in this code :

$q = "UPDATE planet set has_politics = has_politics | 1 ".
"WHERE x='$myrow[x]' AND y='$myrow[y]' AND id!='$Planetid'";
$result = mysql_query ($q, $db);

Then the following code stes "has_politics" again :

$q ="UPDATE planet SET has_politics=$myrow[has_politics] & 0xfe ".
"WHERE id='$Planetid'";
$result = mysql_query ($q, $db);
$myrow["has_politics"] = $myrow["has_politics"] & 0xfe;

0xfe means 254 and I think it adds this to 1 making 255 and then i think 255 is full or something meaning 0 ?
Am i right about this ?

ok so 0xfe is 0 you say

i;ll try some stuff with the code to figure thigns out :)

thnx!
Link to comment
Share on other sites

No. lol, in a word.

"UPDATE my_table SET my_field1=1"

This will set the field in the table to 1.

"UPDATE my_table SET my_field1=1000"

This will now mean that my_field1 is 1000. It will not equal 1001, or 999. It doesnt perform any mathos on what you give it, it just UPDATEs the content of the field you specified with the value you gave it. No addition, no subtraction, it just overwrites what was there with the new data you're giving it.
Link to comment
Share on other sites

The bitwise operators | and & allow you to manipulate specific bits in a field, so you you can use a single byte column to hold 8 separate settings ( where 0 means NO and 1 means YES)

[code]x | 1         (0000 0001)[/code]

will set 'bit 0' to 1 and leave the other bits unchanged

[code]x & 0xFE   (1111 1110)[/code]

will set 'bit 0' to 0 and leave the other bits unchanged


Similarly,

[code]x | 4         (0000 0100)[/code]

will set 'bit 3' to 1 and leave the other bits unchanged

[code]x & 0xFB   (1111 1011)[/code]

will set 'bit 3' to 0 and leave the other bits unchanged



Hope that helps
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.