Bitwise negation gives unexpected result

后端 未结 5 1220
情歌与酒
情歌与酒 2021-01-05 07:40

I am trying to write a bitwise calculator in java, something that you could input an expression such as ~101 and it would give back 10 however when i run this code



        
5条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-05 08:08

    101 in integer is actually represented as 00000000000000000000000000000101 negate this and you get 11111111111111111111111111111010 - this is -6.

提交回复
热议问题