Click here to Skip to main content
12,945,927 members (36,810 online)
Rate this:
 
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 13: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
Top Experts
Last 24hrsThis month
OriginalGriff 4,899
CHill60 3,180
Maciej Los 2,453
Jochen Arndt 1,910
ppolymorphe 1,785


Advertise | Privacy | Mobile
Web01 | 2.8.170518.1 | Last Updated 27 Feb 2013
Copyright © CodeProject, 1999-2017
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