为什么“是"? Access数据库中值为-1的值? [英] Why is "Yes" a value of -1 in MS Access database?
问题描述
我正在查看MS Access中的链接数据.
I'm looking at linked data in MS Access.
是/否"字段的值为-1(是)和0(否).有人可以解释为什么将这种违反直觉的值用于是"吗? (显然,它应该是1和0)
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.
推荐答案
False
的二进制表示形式是0000000000000000
(使用多少位取决于实现方式).如果对它执行二进制NOT运算,它将被更改为1111111111111111
,即True
,但这是有符号整数-1
的二进制表示形式.
The binary representation of False
is 0000000000000000
(how many bits are used depends on the implementation). If you perform a binary NOT operation on it, it will be changed to 1111111111111111
, i.e. True
, but this is the binary representation of the signed integer -1
.
最高有效位置的1
位表示带负号的负数.通过反转所有位并加1来更改数字的符号.这称为 Two的补码.
A bit of 1
at 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.
让我们更改1111111111111111
的符号.首先反转;我们得到:
0000000000000000
Let us change the sign of 1111111111111111
. First invert; we get:
0000000000000000
然后添加一个:
0000000000000001
,这是1
.
Then add one:
0000000000000001
, this is 1
.
这证明1111111111111111
是-1
的二进制表示形式.
This is the proof that 1111111111111111
was the binary representation of -1
.
更新
此外,比较这些值时请勿进行比较
Also, when comparing these values do not compare
x = -1
或
x = 1
相反,请进行比较
x <> 0
这总是给出正确的结果,而与使用的约定无关.大多数实现将任何不等于零的值都视为True
.
this always gives the correct result, independently of the convention used. Most implementations treat any value unequal zero as True
.
这篇关于为什么“是"? Access数据库中值为-1的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!