Solved

! in arithmatic calculations ?

Posted on 2003-10-27
3
198 Views
Last Modified: 2010-04-02
To C++ Experts,

   How do I calculate things like :
  int x = !(!3 & !8) ;
 thanks ....

meow.
0
Comment
Question by:meow00
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 4

Expert Comment

by:n_fortynine
ID: 9630235
what are you trying to do? the & symbol is for bitwise and, not the logic and (&&) I hope you know that.
0
 
LVL 19

Accepted Solution

by:
Dexstar earned 40 total points
ID: 9630259
meow00:

> How do I calculate things like :
>   int x = !(!3 & !8) ;

Okay, let's break it down.

!3 = 0 because 3 = True, and !True = False, and False = 0
!8 = 0 because 8 = True, and !True = False, and False = 0

(!3 & !8) = (0 & 0) = 0

!(0) = !(False) = True = 1

So, int x would have the value of 1.

Hope that helps,
Dex*
0
 

Expert Comment

by:nesrohtretep
ID: 9630426
You are mixing logical (!) and bitwise (&) operators in an expression. It is a very error-prone practice because of the implicit conversions back-and forth so I'd advise you to stick to one or the other or make explicit conversions.

Are you sure that you don't mean to use the bitwise negation (~) rather than ! (logical negation). ~ will revert each individual bit whereas ! always will result in either 0 or 1.

 - Rgds Peter
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
maze travler 6 71
Need some help with Microsoft Visual Studio C++ 2003 5 84
Problem with SqlConnection 4 190
How to Correctly derive class from CWinThread in MFC 4 111
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question