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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:42:27+00:00 2026-06-18T22:42:27+00:00

if (~mask == 0){…} I have encountered this thing in one of the .cpp

  • 0
if (~mask == 0){...}

I have encountered this thing in one of the .cpp files, and I wonder what is does ~ mean in c/c++?

  • 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-18T22:42:28+00:00Added an answer on June 18, 2026 at 10:42 pm

    It’s a tilde and in C++ it means bitwise NOT.

    For an eight-bit unsigned integer named mask with the following bit representation:

    0010 1100
    

    the value of ~mask is:

    1101 0011
    

    Notice how all the bits have been flipped.

    For your if condition (~mask == 0) to evaluate to true:

    ~mask: 0000 0000
     mask: 1111 1111
    

    In such a case, mask has the value 255.

    Apply the same logic to integers of different bit-widths and signedness, as appropriate.

    (Note: In reality, if your system has 32-bit ints, ~mask will be 32-bit even if mask was 8-bit. This is because ~ performs integral promotion. However, I ignore this fact for the above simple examples.)


    Here’s the formal definition:

    [C++11: 5.3.1/10]: The operand of ˜ shall have integral or unscoped enumeration type; the result is the one’s complement of its operand. Integral promotions are performed. The type of the result is the type of the promoted operand. There is an ambiguity in the unary-expression ˜X(), where X is a class-name or decltype-specifier. The ambiguity is resolved in favor of treating ˜ as a unary complement rather than treating ˜X as referring to a destructor.

    As the passage reminds us, do not confuse bitwise NOT for the leading character in the name of a class destructor. It’s interesting that ~ was chosen for destructors; arguably it’s because one could perceive a destructor as the opposite (i.e. logical NOT) of a constructor.

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

Sidebar

Related Questions

I would like to mask a asp page by a div, this one have
I have this: $('#mask').cycle({ fx: 'scrollLeft', timeout: 0, speed: 300, startingSlide: 0 }); But
I have this mask : Let's say I would like to make a bitwise_and
I have a bit-mask of N chars in size, which is statically known (i.e.
How can create a mask input for number that have percent by jQuery? Do
I need to mask a sprite. I followed this tutorial: http://www.raywenderlich.com/4428/how-to-mask-a-sprite-with-cocos2d-2-0 , however the
I have a JFormattedTextField using the following mask formatter: private MaskFormatter maskForInput; maskForInput=new MaskFormatter(####);
I have a mask with a certain numbers of rows and columns. I would
How to mask SSN in a string ? I am have the following scenario
I have mask in textbox 99:99 I need convert to decimal. example: string 12:34

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.