Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
In my database we set 100663296 to be a GM Leader but also this field in the database gets written to for different things, so it changes that number to 100794368 i was told to possible use a bit-wise check to check whether the first number is the same as the second number, and I have googled on using bit-wise checks but got confused as to what to use for my check.
 
Here are some other numbers that change, including the one from above.
 
predefined number   new changed number/ever changing number.
100663296       =       100794368
67108864        =       67239936
117440512       =       2231767040
 
so how should i go about checking these numbers?
 
And here is part of my code that i was using before i noticed the change in the numbers.
 
<pre lang="xml">if (playerData[i].nameflags == 67108864)
{
    playerRows += &#39;&lt;img src =&quot;icons/GM-Icon.png&quot; alt=&quot;GM&quot; title=&quot;GM&quot;&gt;&lt;/img&gt;&#39;;
}</pre>
Posted 27-Feb-13 14:19pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

If you need to check for full bitwise equality of two integers, all you need is just '==' operator, but to use it, you should guarantee that both operands are integers:
 
left = 12323;
right = 12323;
if (left == right)
   alert("Operands are binary equal; I'll guarantee that. :-)");
 
Be very careful though; if at least one of operands is string representing number, not a number, both operands will be considered strings and you can get confusing results:
 
left = "012323";
right = 12323;
if (left != right)
   alert("Operands are not equal, even though they represent 'equal values', as they are compared as strings.");
 
In general, these days, the attempt to operate with strings representing data instead of data itself is a real curse of the beginners; and it's hard to explain to them. It is especially difficult to explain in JavaScript, with its loose-type typing concept, which is itself very complex and hard to understand, behind the illusory simplicity.
 
Finally, if you need to compare separate bits (and, from your question, I don't see this need), you can use binary operators:
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Operators/Bitwise_Operators[^].
 
That's it, basically.
 
—SA
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 BillWoodruff 360
1 Mathew Soji 309
2 DamithSL 225
3 Afzaal Ahmad Zeeshan 202
4 Maciej Los 190
0 OriginalGriff 6,249
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 3,865


Advertise | Privacy | Mobile
Web04 | 2.8.1411019.1 | Last Updated 27 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100