Why Do "Yes/No" Values in Microsoft Access Map to -1 and 0?
The Use of -1 Puzzles Me. I Would Have Expected the Values to Be: No --> 0 Yes --> +1 Is There an Historical Reason Behind the Use of -1 Instead of +1? 4 1...
The use of -1 puzzles me. I would have expected the values to be:
- NO --> 0
- YES --> +1
Is there an historical reason behind the use of -1 instead of +1?
1 Answer
As discussed on Stack Overflow here, Yes/True values appear in Access as -1 because
Yes/Nofields in Access mimicbitfields,Integervalues in Access are signed, two's complement values,No/Falseis represented by 0, and- the only other two's complement value of a 1-bit number is -1. To illustrate, two's complement numbers can have the following values:
3-bit:
bits integer
---- -------
000 0
001 1
010 2
011 3
100 -4
101 -3
110 -2
111 -1
2-bit:
bits integer
---- -------
00 0
01 1
10 -2
11 -1
1-bit:
bits integer
---- -------
0 0
1 -1
For the integer representation of a bit field (i.e., 1-bit), if 0 is No/False then the only other value available for Yes/True is -1.