What is Boolean Logic?
Boolean logic is a very black and white way processing information. First let's start with some simple vocabulary. There are operands and operators. The operators are what does the comparing and decision making, and there are four main operators. The operands are what the operators are working on. This is the information we are looking at.
Operators
The four main operators
&& - true if both operands are true
|| - true if at least one operand is true
xor - true if ONLY one operand is true
! - true if a single operand is false
Let's just assume that:
X is a TRUE statement
Y is a TRUE statement
Z is a FALSE statement
X && Y
This is asking for X and Y to both be true, since they are both true, this expression is TRUE
X || Z
This is asking for X or Z to be true. Again this is a TRUE expression
X xor Y
This is asking for X or Y but not both, to be true. Since they are both true, this expression is FALSE
!X
This is asking for X to be false. Since X is true, this expression is FALSE
!Z
This is asking for Z to be false. Since Z is false, this expression is TRUE
|| - true if at least one operand is true
xor - true if ONLY one operand is true
! - true if a single operand is false
Let's just assume that:
X is a TRUE statement
Y is a TRUE statement
Z is a FALSE statement
X && Y
This is asking for X and Y to both be true, since they are both true, this expression is TRUE
X || Z
This is asking for X or Z to be true. Again this is a TRUE expression
X xor Y
This is asking for X or Y but not both, to be true. Since they are both true, this expression is FALSE
!X
This is asking for X to be false. Since X is true, this expression is FALSE
!Z
This is asking for Z to be false. Since Z is false, this expression is TRUE
Why is this useful?
Boolean logic is used a lot in computer programing. Say your program is searching a database for a certain type of person. They can't be male, or over 65 or under 21. You might run the logic like this:
First run the data through !male (! = not, so this is not male)
Then run the data though Age>21 && Age<65 (&& means both must be true)
Sometimes it helps to think of boolean less as these specific comparisons and more as a True or False way of thinking of things. For example, with the same search... we could think like this:
Is the person male: False
Is the person over 21: True
Is the person under 65: True
True/False, Yes/No, On/Off, 0/1, these are very useful questions to ask a computer with it's binary mind!!
First run the data through !male (! = not, so this is not male)
Then run the data though Age>21 && Age<65 (&& means both must be true)
Sometimes it helps to think of boolean less as these specific comparisons and more as a True or False way of thinking of things. For example, with the same search... we could think like this:
Is the person male: False
Is the person over 21: True
Is the person under 65: True
True/False, Yes/No, On/Off, 0/1, these are very useful questions to ask a computer with it's binary mind!!
Goatella
Follow us on Twitter
New Amazon
New Guestbook
-
-
Akmon37
Jun 27, 2011 @ 10:59 am | delete
- Good lens - very interesting!
-
-
-
GonnaFly
Jun 26, 2011 @ 5:57 am | delete
- This lens has been blessed by the maths angel and added to my best maths resources lens.
-
by angelabradley
Hello Squidoo! My name is Angela & I dabble in lots of things online. I create children's software for the iOS (thats iPod, iPad and iPhone) through my... more »
- 9 featured lenses
- Winner of 6 trophies!
- Top lens » Restoration Druids
Feeling creative?
Create a Lens!
Explore related pages
- Make Money From Home Make Money From Home
- Review & Compare: The No-Fee THRiVE Chequing Account from ING Direct Canada Review & Compare: The No-Fee THRiVE Chequing Account from ING Direct Canada
- Print on Demand Shops Reviewed Print on Demand Shops Reviewed
- Sewing Machines for Beginners Sewing Machines for Beginners
- 10 awesomely useless websites 10 awesomely useless websites
- What is the Best Camera under 200 Dollars in 2012? What is the Best Camera under 200 Dollars in 2012?