Jump to content

Archived

This topic is now archived and is closed to further replies.

pmzq

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

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,

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
0xFE is hexadecimal for decimal 255 I think.

Share this post


Link to post
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.. ?

Share this post


Link to post
Share on other sites
yeah, just swap it. although you should check to make sure your table contains the right character and not that code... otherwise switching to use a number instead could mess with your query results.

Share this post


Link to post
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 :| ???????

Share this post


Link to post
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.

Share this post


Link to post
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!

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
Ok thnx i'm getting it :)

I think i get it now it just putts in a zero i'll try to code things with my code and try if it works!

thnx again!! :)

pMzQ,

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
that was the explanation I was looking for THNX :D

That is exactly what it does :D now I can continue :)

Share this post


Link to post
Share on other sites

×

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.