## Reference.Boolean History

May 16, 2009, at 08:53 AM by David A. Mellis -
Deleted line 7:
May 16, 2009, at 08:53 AM by David A. Mellis -
Changed line 9 from:

to:

Changed lines 12-13 from:

is true only if x is 1, 2, 3, or 4.

to:

is true only if both inputs are high.

September 14, 2007, at 05:48 PM by Paul Badger -
Changed lines 8-9 from:

if (x > 0 && x < 5) {

to:

July 16, 2007, at 02:18 PM by Paul Badger -
Changed line 46 from:
• ^ (bitwise NOT
to:
• ~ (bitwise NOT
July 16, 2007, at 02:17 PM by Paul Badger -
• ^ (bitwise NOT
July 16, 2007, at 02:14 PM by Paul Badger -
• & (bitwise AND)
• | (bitwise OR)
July 16, 2007, at 02:08 PM by Paul Badger -
Changed lines 46-49 from:
to:
April 15, 2007, at 05:29 PM by David A. Mellis -
Changed line 8 from:

if (x > 0 && x< 5) {

to:

if (x > 0 && x < 5) {

Changed line 22 from:

True if the operand is true, e.g.

to:

True if the operand is false, e.g.

April 15, 2007, at 05:28 PM by David A. Mellis -
Changed lines 38-39 from:

[@ if (a >= 10 && a <= 20){} // true if a is between 10 and 20

to:

[@

April 15, 2007, at 05:28 PM by David A. Mellis - matching formatting tags and removing incorrect example.
Changed lines 41-43 from:

digitalWrite(ledPin, !a); // this will turn on the LED every other time through the loop

to:

@]

April 15, 2007, at 04:15 AM by Paul Badger -
Changed lines 29-30 from:

to:

#### Warning

Make sure you don't mistake the boolean AND operator, && (double ampersand) for the bitwise AND operator & (single ampersand). They are entirely different beasts.

Similarly, do not confuse the boolean || (double pipe) operator with the bitwise OR operator | (single pipe).

The bitwise not ~ (tilde) looks much different than the boolean not ! (exclamation point or "bang" as the programmers say) but you still have to be sure which one you want where.

#### Examples

[@ if (a >= 10 && a <= 20){} // true if a is between 10 and 20

if (a >= 10 && a <= 20){} // true if a is between 10 and 20

digitalWrite(ledPin, !a); // this will turn on the LED every other time through the loop

August 01, 2006, at 02:16 PM by David A. Mellis -
Changed lines 5-6 from:

&& (logical and): true only if both operands are true, e.g.

to:

### && (logical and)

True only if both operands are true, e.g.

Changed lines 13-14 from:

|| (logical or): true if either operand is true, e.g.

to:

### || (logical or)

True if either operand is true, e.g.

Changed lines 21-22 from:

! (not): true if the operand is true, e.g.

to:

### ! (not)

True if the operand is true, e.g.

August 01, 2006, at 02:15 PM by David A. Mellis -
Changed lines 5-10 from:

&& (logical and): true only if both operands are true, e.g. if (x > 0 && x< 5) { } is true only if x is 1, 2, 3, or 4.

|| (logical or): true if either operand is true, e.g. if (x > 0 || y > 0) { } is true if either x or y is greater than 0.

! (not): true if the operand is true, e.g. if (!x) { } is true if x is false (i.e. if x equals 0).

to:

&& (logical and): true only if both operands are true, e.g.

```if (x > 0 && x< 5) {
// ...
}
```

is true only if x is 1, 2, 3, or 4.

|| (logical or): true if either operand is true, e.g.

```if (x > 0 || y > 0) {
// ...
}
```

is true if either x or y is greater than 0.

! (not): true if the operand is true, e.g.

```if (!x) {
// ...
}
```

is true if x is false (i.e. if x equals 0).

August 01, 2006, at 02:13 PM by David A. Mellis -

# Boolean Operators

These can be used inside the condition of an if statement.

&& (logical and): true only if both operands are true, e.g. if (x > 0 && x< 5) { } is true only if x is 1, 2, 3, or 4.

|| (logical or): true if either operand is true, e.g. if (x > 0 || y > 0) { } is true if either x or y is greater than 0.

! (not): true if the operand is true, e.g. if (!x) { } is true if x is false (i.e. if x equals 0).