Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7833747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:52:22+00:00 2026-06-02T12:52:22+00:00

I experimented with the bitwise-operator suggested to my question and here . Check the

  • 0

I experimented with the bitwise-operator suggested to my question and here.

Check the results of my testsuite:

function equal(n1,n2){
    var bool = (n1^n2 >= 0)?true:false;
    document.write("<div>"+bool+" ("+(n1^n2)+")</div>");
}


equal(-5,-2);  //true
equal(-4,-20); //true
equal(15,-2);  //false
equal(25,3);   //true 

equal(-1,1);   //false
equal(1,1);    //true
equal(-1,-1);  //true

// edgecases
equal(0,0);
equal(-0,0);
equal(+0,0);
equal(-0,+0);
equal(+0,-0);

outcome:

true (5)
true (16)
true (-15)
true (26)

true (-2)
false (0)
true (0)

true (0)
true (0)
true (0)
true (0)
true (0)

My according fiddle is here.

The result confuses me very much. Am I too stupid? What has happened here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T12:52:24+00:00Added an answer on June 2, 2026 at 12:52 pm

    You had your parentheses in the wrong place:

    function equal(n1, n2){
        var bool = (n1 ^ n2) >= 0 ? true : false;
        document.write("<div>" + bool + " (" + (n1^n2) + ")</div>");
    }
    

    Here’s an updated fiddle with results matching what you expect.

    This is important in this case because all of the bitwise operators are of lower precedence than the relational comparison operators. Also note that the conditional operator (?:) is of lower precedence than all of the bitwise operators, so there’s no need for another set of parentheses around the entire condition.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've experimented with JavaScript and noticed this strange thing: var s = hello world!;
I'm trying to learn how to make & use packages in Java. I've experimented
Anyone experienced exception using below function? tdse.GetObject(tmpFolderWebDavURL, EnumOpenMode.OpenModeView, null, XMLReadFilter.XMLReadAll) as Folder; Seems if
Experimented sending secure emails using C# and was wondering if I have understood things
I have experimented with several different static analyzers for Java, notably Findbugs and PMD.
I've experimented with a number of techniques for monitoring the health of our SQL
I've recently experimented extensively with interfaces and D2010 RTTI. I don't know at runtime
I'm new to SVN and have experimented with it locally on my Dreamhost test
I experimented the following code list<int> a ={1,2}; list<int> b ={3,4}; a.erase(b.begin()); for (auto
I've experimented with keeping Magento under SVN for a few projects now, I've been

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.