Why do "yes/no" values in Microsoft Access map to -1 and 0?
Andrew Henderson
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?
41 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 -12-bit:
bits integer
---- -------
00 0
01 1
10 -2
11 -11-bit:
bits integer
---- -------
0 0
1 -1For 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.