Questions tagged [boolean-operations]

Boolean algebra is the algebra of truth values 0 and 1. The operations are usually taken to be conjunction ∧, disjunction ∨, and negation ¬, with constants 0 and 1.

Boolean algebra is the algebra of truth values 0 and 1. The operations are usually taken to be conjunction ∧, disjunction ∨, and negation ¬, with constants 0 and 1.

464 questions
271
votes
3 answers

Boolean operators && and ||

According to the R language definition, the difference between & and && (correspondingly | and ||) is that the former is vectorized while the latter is not. According to the help text, I read the difference akin to the difference between an "And"…
SFun28
  • 32,209
  • 43
  • 123
  • 233
149
votes
4 answers

Is there XNOR (Logical biconditional) operator in C#?

I'm new to C# and could not find XNOR operator to provide this truth table: a b a XNOR b ---------------- T T T T F F F T F F F T Is there a specific operator for this? Or I need to use !(A^B)?
trailmax
  • 31,605
  • 20
  • 126
  • 225
134
votes
3 answers

Why doesn't c++ have &&= or ||= for booleans?

Is there a "very bad thing" that can happen &&= and ||= were used as syntactic sugar for bool foo = foo && bar and bool foo = foo || bar?
Kache
  • 11,723
  • 10
  • 47
  • 71
90
votes
11 answers

Conditional XOR?

How come C# doesn't have a conditional XOR operator? Example: true xor false = true true xor true = false false xor false = false
Gilad Naaman
  • 5,828
  • 14
  • 48
  • 78
86
votes
2 answers

Element-wise logical OR in Pandas

I would like the element-wise logical OR operator. I know "or" itself is not what I am looking for. I am aware that AND corresponds to & and NOT, ~. But what about OR?
Keith
  • 4,117
  • 5
  • 40
  • 62
83
votes
7 answers

Boolean 'NOT' in T-SQL not working on 'bit' datatype?

Trying to perform a single boolean NOT operation, it appears that under MS SQL Server 2005, the following block does not work DECLARE @MyBoolean bit; SET @MyBoolean = 0; SET @MyBoolean = NOT @MyBoolean; SELECT @MyBoolean; Instead, I am getting more…
Joannes Vermorel
  • 8,551
  • 10
  • 60
  • 95
78
votes
9 answers

Boolean operators vs Bitwise operators

I am confused as to when I should use Boolean vs bitwise operators and vs & or vs | Could someone enlighten me as to when do i use each and when will using one over the other affect my results?
Jiew Meng
  • 74,635
  • 166
  • 442
  • 756
64
votes
4 answers

How to perform element wise boolean operations on numpy arrays

For example I would like to create a mask that masks elements with value between 40 and 60: foo = np.asanyarray(range(100)) mask = (foo < 40).__or__(foo > 60) Which just looks ugly, I can't write: (foo < 40) or (foo > 60) because I end up with:…
jb.
  • 20,419
  • 16
  • 91
  • 130
41
votes
4 answers

VBA: Why would the Not operator stop working?

This has me utterly baffled. Sub testChangeBoolean() Dim X As Boolean ' default value is False X = True ' X is now True X = Not X ' X is back to False End Sub But I'm trying to toggle the .FitText property in…
eluhnabroad
  • 433
  • 3
  • 8
38
votes
2 answers

Logical operation on two columns of a dataframe

In pandas, I'd like to create a computed column that's a boolean operation on two other columns. In pandas, it's easy to add together two numerical columns. I'd like to do something similar with logical operator AND. Here's my first try: In [1]: d…
dinosaur
  • 2,675
  • 3
  • 23
  • 39
30
votes
24 answers

Why do most programming languages only have binary equality comparison operators?

In natural languages, we would say "some color is a primary color if the color is red, blue, or yellow." In every programming language I've seen, that translates into something like: isPrimaryColor = someColor == "Red" or someColor == "Blue" or…
Davy8
  • 29,246
  • 22
  • 107
  • 172
29
votes
7 answers

Using NOT operator in IF conditions

Is it really a good practice to avoid using NOT operator in IF conditions in order to make your code better readable? I heard the if (doSomething()) is better then if (!doSomething()).
Eugene
  • 55,777
  • 85
  • 212
  • 324
27
votes
5 answers

Are there builtin functions for elementwise boolean operators over boolean lists?

For example, if you have n lists of bools of the same length, then elementwise boolean AND should return another list of that length that has True in those positions where all the input lists have True, and False everywhere else. It's pretty easy to…
bshanks
  • 1,198
  • 1
  • 11
  • 24
27
votes
6 answers

Using "and" and "or" operator with Python strings

I don't understand the meaning of the line: parameter and (" " + parameter) or "" where parameter is string Why would one want to use and and or operator, in general, with python strings?
rok
  • 5,653
  • 13
  • 48
  • 89
25
votes
22 answers

How can I write like "x == either 1 or 2" in a programming language?

Possible Duplicate: Why do most programming languages only have binary equality comparison operators? I have had a simple question for a fairly long time--since I started learning programming languages. I'd like to write like "if x is either 1 or…
Culip
  • 491
  • 4
  • 17
1
2 3
30 31