为什么 Microsoft Access 中的“是/否”值映射到 -1 和 0?

Ale*_*Ale 4 microsoft-access

-1 的使用让我感到困惑。我原以为这些值是:

  • 否 --> 0
  • 是--> +1

使用 -1 而不是 +1 背后是否有历史原因?

Gor*_*son 5

正如此处堆栈溢出所讨论的,Yes/True值在 Access 中显示为 -1,因为

  • Yes/NoAccess 中的bit字段模拟字段,
  • IntegerAccess 中的值是有符号的,二进制补码值,
  • No/False 由 0 表示,并且
  • 1 位数字的唯一其他二进制补码值为 -1。为了说明,二进制补码数可以具有以下值:

3 位:

bits  integer
----  -------
000         0
001         1
010         2
011         3
100        -4
101        -3
110        -2
111        -1
Run Code Online (Sandbox Code Playgroud)

2 位:

bits  integer
----  -------
00          0
01          1
10         -2
11         -1
Run Code Online (Sandbox Code Playgroud)

1 位:

bits  integer
----  -------
0           0
1          -1
Run Code Online (Sandbox Code Playgroud)

对于bit字段的整数表示(即 1 位),如果 0 是No/False那么唯一可用的其他值Yes/True是 -1。