|
|
On 12-Sep-08 21:14, Vincent Le Chevalier wrote:
> andrel a écrit :
>>>>> Which one is FALSE? Is that 0 or 1? I know it's one or the other,
>>>>> but I can never ever remember which - and it's kind of important!
>>>>
>>>> 0. Any other value is true.
>>>
>>> I remember that 0 is one thing and everything else is the opposite.
>>> But I can never remember which is which.
>>
>> It's easy, booleans are a sort of integers following the normal
>> convention that 0 is false and 1 is true. That any other value also
>> works comes from the fact that most processors have a zero flag that
>> you can conditionally jump on. Another example of hardware influencing
>> the language.
>
> There is also a similarity between the behaviours of positive integers,
> multiplication and addition, and booleans, AND and OR. That is:
>
> Integers Booleans
> a*(b+c) = a*b + a*c a AND (b OR c) = (a AND b) OR (a AND c)
> 0 + a = a false OR a = a
> 0 * a = 0 false AND a = false
> if a>0, a+b>0 for all b if a is true, a OR b is true for all b
> And so on...
>
> It does not work out that well if you set true <-> 0.
>
If you take
true <-> 0
false <-> 1
OR <-> *
AND <-> +
it works again.
Post a reply to this message
|
|