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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:45:58+00:00 2026-06-13T06:45:58+00:00

I can’t get the 2-complement calculation to work. I know C compiles ~b that

  • 0

I can’t get the 2-complement calculation to work.

I know C compiles ~b that would invert all bits to -6 if b=5. But why?

int b=101, inverting all bits is 010 then for 2 complement’s notation I just add 1 but that becomes 011 i.e. 3 which is wrong answer.

How should I calculate with bit inversion operator ~?

  • 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-13T06:45:59+00:00Added an answer on June 13, 2026 at 6:45 am

    ~b is not a 2-complement operation. It is a bitwise NOT operation. It just inverts every bit in a number, therefore ~b is unequal to -b.

    Examples:

    b = 5
    binary representation of b:  0000 0000 0000 0101
    binary representation of ~b: 1111 1111 1111 1010
    ~b = -6
    
    b = 17
    binary representation of b:     0000 0000 0001 0001
    binary representation of ~b:    1111 1111 1110 1110
    ~b = -18
    binary representation of ~(~b): 0000 0000 0001 0001
    ~(~b) = 17
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can you cast a List<int> to List<string> somehow? I know I could loop through
Can anyone let me know how can we change the value of kendo combobox
Can I change the field public virtual ClassOne ClassOne { get; set; } to
Can any one tell, how to get the result of LINQ query contains group
Can we change the color of the divider? Apple documentations says, that we can
Can someone please explain why this doesn't work? MyClass myClass1 = new MyClass(); object
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Can anyone tell me how an IDE like NetBeans or any for that matter
Does anyone know how can I replace this 2 symbol below from the string
Can i get the source code for a WAMP stack installer somewhere? Any help

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.