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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:18:39+00:00 2026-06-13T23:18:39+00:00

I have been performing bitwise operation on a variable. int p=3,q=5; int a=~p,b=~q; //complement

  • 0

I have been performing bitwise operation on a variable.

int p=3,q=5;
int a=~p,b=~q; //complement a and b
printf("%d %d\t%d %d",p,a,q,b);

The theoretical output for ‘b’ is 10 and in case if it’s signed, it has to be -2.
But the output is -6.

Can someone explain me the working of it?

  • 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-13T23:18:40+00:00Added an answer on June 13, 2026 at 11:18 pm

    ~ is the bitwise complement operator in c (or python) which essentially calculates -x - 1.

    So a table would look like:

    0  -1
    1  -2
    2  -3
    3  -4 
    4  -5 
    5  -6
    

    In two’s complement representation, if a number x’s most significant bit is 1, then the actual value would be −(~x + 1).

    For instance,

    0b11110000 = -(~0b1111 + 1) = -(15 + 1) = -16.
    

    This is a natural representation of negative numbers, because

    0000001 =  1
    0000000 =  0
    1111111 = -1  (wrap around)
    1111110 = -2
    1111101 = -3 etc.
    

    See http://en.wikipedia.org/wiki/Two%27s_complement for detail.

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

Sidebar

Related Questions

Have been looking on some tutorials for drawing canvas using SurfaceView, but the only
Have been searching how to convert a dictionary to a string. But the results
I have been experimenting with geography datatype lately and just love it. But I
Sorry if this has been covered - I've been looking for hours but I
Well I have been reading quite a lot sources but they differ in definiton:
I am new to using ajax but have been using PHP for awhile. I
In C# I have been performing a FindAll in a generic list as follows:
I have been looking everywhere but can't seem to find a good solution for
I have been performing unit tests on my iOS4.1 iPhone app successfully. I am
I have been performing timing measurements on an application that communicates to a device

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.