473,385 Members | 1,927 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Boolean problem

Hi guys! I would like to know if anyone can help me with this:
i must make a difference between two variables ('t' and 'o') which are both boolean: t-0. i don't know how i can do it, and i would appreciate if anyone could help me. the language is C++.
thanks
anoris
Oct 6 '07 #1
6 1240
what do you mean by "making a diffrence" ?
Oct 6 '07 #2
what do you mean by "making a diffrence" ?
sorry the "bad language"
a quantity minus outher.something like the mathematical subtraction:
5-3=2
Oct 6 '07 #3
Ganon11
3,652 Expert 2GB
If your variables are both booleans, then you have a few possibilities:

T and O are both TRUE. C++ represents TRUE as 1, so you will have 1-1 = 0, which is interpreted as FALSE.

T and O are both FALSE - this is 0-0 = 0 which is FALSE.

T is TRUE and O is FALSE, then you have 1-0 = 1 which is TRUE. Alternatively, if T is FALSE and O is TRUE, then you have 0-1 = -1 which I think is also TRUE.
Oct 7 '07 #4
Laharl
849 Expert 512MB
Alternatively, if T is FALSE and O is TRUE, then you have 0-1 = -1 which I think is also TRUE.
-1 should be TRUE, since 0-1 is equivalent to 1-0 in truth value, as the - basically represents an OR relationship.
Oct 7 '07 #5
Yes, I know all of that, but what I really wanted to know was how to do it in C++. I will need that result to do other things. Meanwhile I spoke to a colleague of mine which said that I could do the code like this:
Expand|Select|Wrap|Line Numbers
  1. bool g, t, o;
  2. (...)
  3. g=t^o;
  4.  
and the result, g, would always give me the expected value. I checked, and, as a matter of fact, the result that appears is always what it should give. What I would now like to know is if this is a correct way of doing it, or if any problem will come out of this. If anyone knows anything about this, than I would be really appreciate.
Anoris
Oct 7 '07 #6
JosAH
11,448 Expert 8TB
Yes, I know all of that, but what I really wanted to know was how to do it in C++. I will need that result to do other things. Meanwhile I spoke to a colleague of mine which said that I could do the code like this:
Expand|Select|Wrap|Line Numbers
  1. bool g, t, o;
  2. (...)
  3. g=t^o;
  4.  
and the result, g, would always give me the expected value. I checked, and, as a matter of fact, the result that appears is always what it should give. What I would now like to know is if this is a correct way of doing it, or if any problem will come out of this. If anyone knows anything about this, than I would be really appreciate.
Anoris
There is no arithmetic '-' (minus) defined for a Boolean algebra; the 'difference'
of two boolean values could be defined as 'a^b', what you did, and it is equivalent
to 'a != b' which maybe looks less cryptic.

kind regards,

Jos
Oct 7 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: greg | last post by:
Discussion is invited on the following proto-PEP. ------------------------------------------------------------- PEP ??? - Overloadable Boolean Operators...
5
by: asim | last post by:
Hi if a declare a variale say Dim Flag and assing it to true a boolean value Flag = True and if i try to concatinate it with another string like mystr="<my-str>" & Flag & "</my-str>" and if...
8
by: Metro Sauper | last post by:
Why is the default text representation for booleans in C# 'True' and 'False' whereas in xml it is 'true' and 'false'? It seems like it would make sense to have them both the same. Metro T....
2
by: Raj | last post by:
Hi, When we are sorting the DataGrid Boolean column the grid is becoming redcross. I have my own PPMIPDataGridBoolColumn class inherited from System.Windows.Forms.DataGridBoolColumn. In this...
7
by: Pep | last post by:
This is getting weird. I have to keep moving between visual c and gnu c++ compilers and now have come across a problem that seems to relate to the boolean datatype. I have a method that is...
1
by: vbisjustforme | last post by:
Hello, I am working on a windows dll and this is my problem: 'api Public Declare Function myFunction Lib "Functionmine.dll" (byval ProgieName as String) as Boolean 'entry point in module...
4
by: Ironr4ge | last post by:
Hi everyone, I am trying to open the form "Languages" with a diffrent record source to the "Contacts" form where I conducted the search or filter... . I was wondering whether there was a vba...
3
by: c2 | last post by:
hi, i face a problem when click the icon , my login will prompt this message String was not recognized as a valid Boolean See the end of this message for details on invoking just-in-time (JIT)...
11
by: JeffP | last post by:
Just have a small problem with boolean fields in a list box showing as 0 and -1, not Yes/No or True/False. Is there any fix to this? -- Jeff "More Access Stuff." http://www.asken.com.au
19
by: tshad | last post by:
I have a value in my sql table set to tinyint (can't set to bit). I am trying to move it into a boolean field in my program and have tried: isTrue = (int)dbReader and isTrue =...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.