Im having trouble understanding AND OR and NOT
can someone clarify these.
Im having trouble understanding AND OR and NOT
can someone clarify these.
Those aren't bools.. they are logical operators.
one and a one is a one.
one and a zero is a zero.
zero and a one is a zero.
zero and a zero is a zero.
one or a one is a one.
one or a zero is a one.
zero or a one is a one.
zero or a zero is a zero.
Not one is zero.
Not zero is one.
1 AND 1 = 1
1 AND 0 = 0
0 AND 1 = 0
0 AND 0 = 0
1 OR 1 = 1
1 OR 0 = 1
0 OR 1 = 1
0 OR 0 = 0
NOT 1 = 0
NOT 0 = 1
There really is nothing to understand. It is one of those 'I believe' things. Just remember any zero in an AND equation makes the equation zero. Any one in an OR equation makes the equation one. A NOT of a one or zero is it's opposite.
Bool...
TRUE
FALSE
where
TRUE = 1
FALSE = 0
so
TRUE AND FALSE = FALSE
TRUE or FALSE = TRUE
NOT(TRUE) = FALSE
etc
Blue
cant put it any other way...
i suggest tho, when you are using your logical operators, make sure you understand your condition.
note:
if (!(mybool))
/....
and
if(mybool == false)
/...
the second one is easier to read. if you are beginning you should stick to readablility.
Just look at it like this.
If I declare bool poop=true;
then if(poop) means if(poop==true)
if (!poop) means if (poop==false)
and also, false is a 0 and true is a 1.
TRUE is not always 1 and FALSE is not always 0!
In electronics it is sometimes defined that TRUE is 0 and FALSE is 1. A zerosignal means that everything is OK. But when a sensor notices a failure it will send a pulse, which is a onesignal. So in that case FALSE is 1 and TRUE is 0. So to handle the failure one would do:
if (error)
{
// handle error
}
But also in software TRUE is not always 1 and FALSE not always 0.
>>TRUE is not always 1 and FALSE is not always 0!
That's true...

Isn't FALSE always 0? I thought FALSE = 0 and TRUE = nonzeroOriginally posted by Shiro
TRUE is not always 1 and FALSE is not always 0!
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
>Isn't FALSE always 0? I thought FALSE = 0 and TRUE = nonzero
Generally, but the actual values of TRUE and FALSE are up to the implementation. If you want TRUE to be 20 and FALSE to be 4756 then you can do so and anyone who uses your code will have to accept that.
Prelude
My best code is written with the delete key.
Well when you are using an anal compiler you may have a backwards value list.
but when you are in a program environment, the compiler takes a non zero as true and a 0 as false, but on the other hand, any returns to the OS', the operating systems process index, will look at the return value as 0 successful and 1 not successful. so when returning from a function and returning from main , there is a difference... else your compiler is almost guarenteed to be true non zero and false 0. because almost all hardware (yes almost all) define, 0 as off and 1 as on. if its the other way around, then its outta sync with the standard.
and besides, if you using your booleans, then a true is a true no matter what... so test for a true and not a number value.