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.

526 questions
3459
votes
104 answers

How can I convert a string to boolean in JavaScript?

Can I convert a string representing a boolean value (e.g., 'true', 'false') into a intrinsic type in JavaScript? I have a hidden form in HTML that is updated based upon a user's selection within a list. This form contains some fields which represent…
Kevin
  • 7,856
  • 11
  • 35
  • 40
324
votes
5 answers

Difference between Boolean operators && and & and between || and | in R

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"…
Suraj
  • 35,905
  • 47
  • 139
  • 250
195
votes
5 answers

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

I could not find an 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
  • 34,305
  • 22
  • 140
  • 234
153
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
  • 15,647
  • 12
  • 51
  • 79
106
votes
12 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
  • 6,390
  • 15
  • 52
  • 82
106
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
  • 84,767
  • 185
  • 495
  • 805
99
votes
3 answers

Element-wise logical OR in Pandas

I am aware that AND corresponds to & and NOT, ~. What is the element-wise logical OR operator? I know "or" itself is not what I am looking for.
Keith
  • 4,646
  • 7
  • 43
  • 72
96
votes
2 answers

Inverting a numpy boolean array using ~

Can I use ~A to invert a numpy array of booleans, instead of the rather awkward functions np.logical_and() and np.invert()? Indeed, ~ seems to work fine, but I can't find it in any nympy reference manual, and - more alarmingly - it certainly does…
Rolf Bartstra
  • 1,643
  • 1
  • 16
  • 19
88
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.
  • 23,300
  • 18
  • 98
  • 136
86
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,976
  • 12
  • 64
  • 104
59
votes
3 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
  • 3,164
  • 4
  • 28
  • 40
41
votes
3 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
32
votes
8 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
  • 59,186
  • 91
  • 226
  • 333
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
  • 30,868
  • 25
  • 115
  • 173
29
votes
6 answers

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

I don't understand the meaning of the Python code line: parameter and (" " + parameter) or "" which is using strings along with logical operators and and or. Also the type of the variable parameter is a string. In this context, as I can't imagine a…
rok
  • 9,403
  • 17
  • 70
  • 126
1
2 3
35 36