Logic 使用&;,~在sybase中

Logic 使用&;,~在sybase中,logic,sybase,logical-operators,Logic,Sybase,Logical Operators,我正在执行以下声明 选择10&~3。这将输出为8 选择10&~5。这将输出为10 选择10&~2。这将输出为8 有人能解释这背后的逻辑吗?这是按位运算,~是逆运算 3 is the same as 0011 in binary, and inverse of that is 1100 2 is the same as 0010 in binary, and inverse of that is 1101 5 is the same as 0101 in binary, and inverse o

我正在执行以下声明

选择10&~3。这将输出为8 选择10&~5。这将输出为10 选择10&~2。这将输出为8


有人能解释这背后的逻辑吗?

这是按位运算,~是逆运算

3 is the same as 0011 in binary, and inverse of that is 1100
2 is the same as 0010 in binary, and inverse of that is 1101
5 is the same as 0101 in binary, and inverse of that is 1010
10 is the same as 1010 in binary.

10 & ~3 => 1010 & 1100 = 1000 => 8
10 & ~5 => 1010 & 1010 = 1010 => 10
10 & ~2 => 1010 & 1101 = 1000 => 8
按位是逐位的


你也可以用十进制思维,但你也必须用二进制思维(顺序1、2、4、8、16、32、64、128…)。10由“8 | 2”组成,3由“1 | 2”组成。3的倒数几乎等于“1 | 2”。10和3之间的公共部分是2,因此您将拥有10中不在3中的所有部分,从而为我们提供8。

感谢Lostfields。