robin wrote:
>> Date: Wed, 23 Mar 2005 17:39:06 -0700
>> From: James Giles <[log in to unmask]>
...
>> Before C the most common "under the hood" implementation
>> of logicals I came across was negative means .true. and positive
>> means .false. That's because almost all hardware had a conditional
>> branch based on the sign bit of an operand register.
>
> Hardware also had conditionals based on zero/non-zero,
> and thus 0 = false and 1 = true is equally possible,
> and more convenient, particularly when logical hardware
> instructions are used (e.g., for x .or. y, and x .and. y
> etc.) [...]
The sign bit is *exactly* as convenient. Logical hardware
instructions operate on the sign bit too (and all the other bits).
As correctly pointed out by another, the canonical representation
and the testing method are somewhat independent. Assuming two's
complement integers, the canonical representation that travels best
is -1 for true and 0 for false. With that pair of canonical values,
you can use hardware branches based on sign, zero/nonzero, even/odd,
or any other bit you like. And the hardware AND, OR, XOR and
such all operate just fine.
> Indeed, PL/I uses 1 for true and 0 for false (stored as a single bit).
How do you know? A single bit *signed* integer can hold the values
-1 and 0. If all you've got is a single bit, that's also the sign bit.
--
J. Giles
"I conclude that there are two ways of constructing a software
design: One way is to make it so simple that there are obviously
no deficiencies and the other way is to make it so complicated
that there are no obvious deficiencies." -- C. A. R. Hoare
|