+ 5

Equality and complement operator

Why x = 0 ?? Here 👇👇 Or how is the complement of 0 gives -1 ??? https://code.sololearn.com/clyjS6Sy2UNC/?ref=app

26th Jul 2020, 3:05 AM
Ahmed Mahmoud
Ahmed Mahmoud - avatar
2 ответов
+ 7
Well in C for any integer n, bitwise complement of n will be -(n+1). To understand this, you should have the knowledge of 2's complement. It works like this First it converts the given decimal number to its corresponding binary value.That is in case of 0 it converts it to 0000 0000 (to 8 bit binary number). Then it converts it to the ones complement , 1111 1111 that is the 2's complement representation of -1 So -1 == ~0 outputs 1(true) x = 1 - 1
26th Jul 2020, 3:49 AM
Anis
Anis - avatar
+ 2
i got it thanks 🌺
26th Jul 2020, 4:07 AM
Ahmed Mahmoud
Ahmed Mahmoud - avatar