The ~(Complement) Operater | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 1

The ~(Complement) Operater

How this complement operator works https://code.sololearn.com/cy9GB7FHG9US/?ref=app

15th Jun 2022, 7:42 AM
Irfan Ansari
Irfan Ansari - avatar
5 Respostas
+ 2
Result is the operand's value with its sign inverted (negative <-> positive) subtracted by 1. In your code ... 3 with sign inverted becomes -3, subtract by 1, becomes -4. -4 with sign inverted becomed 4, subtract by 1, becomes 3.
15th Jun 2022, 7:53 AM
Ipang
+ 2
Irfansari, See the top answer in the following page https://www.quora.com/How-does-the-bitwise-complement-operator-work
15th Jun 2022, 8:17 AM
Ipang
+ 1
Ipang but what is going on in computer
15th Jun 2022, 7:56 AM
Irfan Ansari
Irfan Ansari - avatar
+ 1
The bitwise not (~) operator simply flips all bits to their opposite values. If a bit is 0, it becomes 1. If a bit is 1, it becomes 0. It is also called one's complement. What you see in your program is the result of taking the one's complement of 3, and displaying it as two's complement. Two's complement is the most common way to interpret negative values. It will always be off by 1 from the one's complement.
15th Jun 2022, 9:58 AM
Brian
Brian - avatar
+ 1
Nice what a think it's a very good programeršŸ‘
16th Jun 2022, 10:40 AM
Iron hunt šŸ¾
Iron hunt šŸ¾ - avatar