SQL按位不(~)

标签 sql bit-manipulation

谁能解释一下原因

select ~1

给出结果

-2

也许我对数字类型的实际位有很多了解。你会推荐什么资源?

最佳答案

问:有人可以解释为什么选择 ~1 给出结果 -2 吗?

A:出于同样的原因,~0 会给出 -1 :)

这是一篇关于“二进制补码”算法的好文章:

大多数 CPU 架构都是二进制补码(相对于一个的补码)。来自同一篇文章:

Two's complement is the easiest to implement in hardware, which may be the ultimate reason for its widespread popularity[citation needed]. Processors on the early mainframes often consisted of thousands of transistors – eliminating a significant number of transistors was a significant cost savings. The architects of the early integrated circuit-based CPUs (Intel 8080, etc.) chose to use two's complement math. As IC technology advanced, virtually all adopted two's complement technology. Intel, AMD, and Power Architecture chips are all two's complement.

关于SQL按位不(~),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16286519/

相关文章:

php - 在PHP中将当前日期添加到mysql数据库

php - MySQL WHERE 基于 PHP 变量

java - 位移位操作不返回预期结果

将两个无符号字符连接为一个 uint16_t

mysql left outer join 有两个条件

python - 音乐轨道数据库

MySQL 解决错误 1093

c - 在c中使用位操作向右旋转

C++ return bool with && in return statement - 需要澄清

algorithm - 无除法快速平均