I would not count on the following definition, which should be true at the bytecode level.
true == 1
At the binary level (and its near linguistic independence), a logical value is usually defined as
false == 0 true != 0
The javac compiler apparently also follows this definition (all the checks in the javac byte codec that I saw always check ZERO again, never against ONE).
And it makes sense to use this definition for boolean instead of treating only 1 as true, C also defines it that way (true is simple! = 0, not just 1), and in the assembly code this convention is also widely used. Thus, java also uses this definition, allowing you to receive / pass java Booleans to other code without any special conversions.
I suspect your first code example (with ifeq) is the only way to correctly implement a non-operator for booleans. ^ 1-method (xor with 1) will not be executed if the logical value is not represented as 0/1. Any other int value will cause the expression to work incorrectly.
Durandal
source share