4

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
  • 2
    -1, in twos-complement, is a number whose bits are all 1. Dec 30, 2013 at 17:12
  • 4
    One of the reasons for this are because booleans within MS Access can also have no value or Null values. As I thought the reason for it being -1 is because of the type of integer data type a boolean is defined as. "This is because the Boolean data type is stored as a 16-bit signed integer." The actual binary value of -1 is 1111111111111111. This question has been asked several times on SO stackoverflow.com/questions/8827447/…
    – Ramhound
    Dec 30, 2013 at 17:14
  • @Ale - This also comes down to base 2 arithmetic. A bitwise NOT of anythng but 11111111 11111111 would not result in 00000000 00000000. The logical bitwise NOT of False should be True and vice versa.
    – Ramhound
    Dec 30, 2013 at 17:21
  • @Ramhound Actually, Yes/No fields in Access cannot be Null, only Yes/True or No/False. If you try to force a Yes/No field to Null it simply becomes No/False. Feb 2, 2014 at 13:24

1 Answer 1

5

As discussed on Stack Overflow here, Yes/True values appear in Access as -1 because

  • Yes/No fields in Access mimic bit fields,
  • Integer values in Access are signed, two's complement values,
  • No/False is 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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .