Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果有一个 11 位二进制补码数,范围为 -1024 到 1023,如果超出该范围会发生什么?例如,我有 -1024 并且我减 1。或者我有 1023 并且我加 1。它会崩溃吗?保持不变?换个号码?
-1025 不能用 11 位二进制补码数表示。如果我们添加它们,就会出现溢出:
-1024 = 10000000000 => 11 bits -1 = +11111111111 => 11 bits ------------ 101111111111 => 12 bits
接下来会发生什么取决于您的实施。由于这是一个固定宽度二进制数的问题,我们删除溢出位,留下01111111111or 1023。
01111111111
1023
Stack Overflow 上有很多 类似的 问题,您可能想看看。