booleanlanguage-designinternal-representation

Boolean true - positive 1 or negative 1?


I'm designing a language, and trying to decide whether true should be 0x01 or 0xFF. Obviously, all non-zero values will be converted to true, but I'm trying to decide on the exact internal representation.

What are the pros and cons for each choice?


Solution

  • 0 is false because the processor has a flag that is set when a register is set to zero.

    No other flags are set on any other value (0x01, 0xff, etc) - but the zero flag is set to false when there's a non-zero value in the register.

    So the answers here advocating defining 0 as false and anything else as true are correct.

    If you want to "define" a default value for true, then 0x01 is better than most: