- 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 Antworten
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