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 9218697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:55:25+00:00 2026-06-18T02:55:25+00:00

I am operating on individual bits of two integers, (i am using g++ for

  • 0

I am operating on individual bits of two integers, (i am using g++ for compilation on Ubuntu machine).

In some intermediate step, I have the bit representations as

q = 11000000000000000000000000000000
q_1 = 00000000000000000000000000000001

Now I want to check whether unit’s places of q and q_1 are both same or not. so, I am checking (*q)&1==q_1 in the if condition, and its working fine.

But whenever I want to check that unit’s place of q is 0 and that of q_1 is 1, I thought I should do ((*q)&1==0) && (q_1==1), but it is not working out as expected. For debugging, I cout ed the values of ((*q)&1==0) and (q_1==1) individually and they got printed as 1. However, the value of ((*q)&1==0) && (q_1==1) got printed as 0. Why?

*EDIT : * In the function, q was passed by reference, so I am using *q to get the value..

  • 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-18T02:55:26+00:00Added an answer on June 18, 2026 at 2:55 am

    In C and C++, the bitwise & operator actually has lower precedence than the equivalence operator ==. You’ll need to wrap your bitwise operators in parentheses.

    So:

    ((*q)&1==0) && (q_1==1)
    

    should be:

    (((*q)&1)==0) && (q_1==1)
    

    See: http://en.cppreference.com/w/cpp/language/operator_precedence

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

Sidebar

Related Questions

Right now I'm using this to set/unset individual bits in a byte: if (bit4Set)
I am quite unfamiliar with operating on individual bits. This question is more of
My question concerns bit manipulation when the endianess changes. In particular I have some
I have one query with 21072 individual update statements in SSMS. I am using
Operating System: OSX Method: From the command line, so using sed, cut, gawk, although
What operating system and UI toolkit is this? It's not some fake Hollywood user
I'm developing an app. The operating system I'm using is linux. I need to
Have to erase some of the details of this, but basically I'm trying to
I have a service where some validation rules must be checked before a particular
I had a 2x2 array that I had two threads operating on. it is

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.