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.
这是问题
我想向右移动 31 以获取符号位,但从技术上讲,0 不能是正数和负数吗?
您可以这样尝试32 bit int:-
32 bit int
(x >> 31) | (((~x + 1) >> 31) & 1)