简体   繁体   中英

Why complement of 0 is -1?

I was learning about bitwise operators and I learnt that complement of 0 is 1 and 1 is 0. But when I tried using ~0 on IDLE, it printed -1 and when i typed ~1 it gave -2..

-1 is 0-1 => 00..00-00...01  = 1..11

So, as long as you consider some finite width (width is the size of integer or binary form you are using,4,8....),it is true that:

 00..00 =~11..11 

then, the following also be true:

~0=-1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM