Why ~0 == -1 ? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
- 1

Why ~0 == -1 ?

I saw this prompt in a challenge the other day. I know that tilde (~) is the logical NOT operator and returns rhe complement of the implemented number but Ä° wonder why it returns -1 for 0??

21st Sep 2020, 9:55 AM
Almina GƶkƧe ƇiƧek
4 Respostas
21st Sep 2020, 9:57 AM
The future is now thanks to science
The future is now thanks to science - avatar
+ 2
21st Sep 2020, 9:57 AM
Almina GƶkƧe ƇiƧek
0
Formula of find bitwise complement x=-(x+1) Here x = 0 So bitwise compliment is -(0+1) => x=-(0+1) => x=-1 So answer will be -1 https://www.sololearn.com/learn/4076/?ref=app
21st Sep 2020, 10:52 AM
Vadivelan
0
Idk, sorry
22nd Sep 2020, 3:37 AM
Nelixus
Nelixus - avatar