Thread: Need help understanding !NOT

  1. #1
    Registered User
    Join Date
    Jun 2004

    Need help understanding !NOT

    Good afternoon everyone.

    I have a simple assignment statement:


    My problem is understanding the ! (NOT). If something is not 50, it is false, which returns a value of 0. I would calculate var=335. Is this correct? I know the !50 is a logical operation, which I read as returning TRUE or False. My difficulty is converting that T/F return value (0 or 1) and using it as part of an arithmetic calculation. Is there some place I can read up on this to help grasp the concept?

    Thanks for your help

  2. #2
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Umm... Will this do it for you?
    int convert(bool in) {
       return ((in) ? 1 : 0);

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    !0 is 1
    ! of anything which isn't zero is 0

    Imagine !x as if ( x == 0 )
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Visalia, CA, USA
    Quote Originally Posted by nickadeemus2002
    Good afternoon everyone.
    var = ((5*67)+!50);
    var = ((5*67)+0);
    Are the same. Indeed your example is just a waste of code since you would normally just do

    var = 335; // as you had previously mentioned
    You should use the ! operator with variables, not constants.

    var = !x; // acceptable code
    var = !0; // code that only will generate confusion later.
    There is nothing wrong with using ! with constants except for the fact that it obfuscates your code.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Understanding Headers
    By AeonMoth in forum C++ Programming
    Replies: 2
    Last Post: 06-27-2007, 05:53 AM
  3. trouble understanding the source file structure
    By Mario F. in forum C++ Programming
    Replies: 5
    Last Post: 05-26-2006, 06:46 PM
  4. Replies: 8
    Last Post: 10-24-2005, 11:26 AM
  5. understanding recursive functions
    By houler in forum C Programming
    Replies: 7
    Last Post: 12-09-2004, 12:56 PM