I believe that this was an arbitrary decision, returning to the language of the ancestors of B.
Quoting Link for users to B :
The relational operators < (less than), <= (less than or equal to), > (more) and >= (greater than or equal) take integer rvalue values. The result is one if the operands are in this relation to each other. Otherwise, the result is zero.
There is no explanation for this particular choice and no explanation in ANSI C Justification or the 1978 edition of Kernigan and Ritchie's book The C Programming Language (K & R1).
(In the BCPL of the ancestral language, it had true and false literals, and true represented with all bits set to 1 )
A language could be defined in different ways, and it would still be internally consistent. For example, a standard might say that relational and equality operators result in 0 if the condition is false or any arbitrary non-zero value if the condition is true. The result could be correctly used in the if or in any other context that requires a condition. And itβs easy to imagine a processor on which it is more efficient so that the true value is represented as βall-bit-oneβ, and not as 1 , but the language standard does not allow this.
Several standard library functions, such as isdigit() , can return any arbitrary non-zero value to indicate a true condition, which once again demonstrates that it was an arbitrary choice. ( isdigit , of course, is implemented through a table search, which can give values ββother than 0 and 1 ).
There is some added benefit in that equalities and relational operators give 0 and 1 . For example, this simplifies the calculation of the number of conditions:
int count = 0; count += x == y; count += foo > bar; count += this <= that;
I assume it was convenient to use 0 and 1 in the first B compiler, the behavior was documented, and it has been inherited to this day. Changing the definition would result in the loss of code depending on the previous definition.
And even if it is relatively inefficient in some systems, this is not a huge problem. The result of an equality or relational operator is usually not stored anywhere, so the compiler can present the result, but it likes it so long as the behavior is incompatible. In some cases, it may be necessary to generate code to normalize the result to 0 or 1 , but this is unlikely to be significant.