I’m looking at linked data in MS Access.
The “Yes/No” fields contain the value -1 for YES and 0 for NO. Can someone explain why such a counter-intuitive value is used for “Yes”? (Obviously, it should be 1 and 0)
I imagine there must be a good reason, and I would like to know it.
The binary representation of
Falseis0000000000000000(how many bits are used depends on the implementation). If you perform a binary NOT operation on it, it will be changed to1111111111111111, i.e.True, but this is the binary representation of the signed integer-1.A bit of
1at the most significant position signals a negative number for signed numbers. Changing the sign of a number happens by inverting all the bits and adding 1. This is called the Two’s complement.Let us change the sign of
1111111111111111. First invert; we get:0000000000000000Then add one:
0000000000000001, this is1.This is the proof that
1111111111111111was the binary representation of-1.UPDATE
Also, when comparing these values do not compare
or
instead, do compare
this always gives the correct result, independently of the convention used. Most implementations treat any value unequal zero as
True.