Unable to understand. Why output is "equal"
code:
if (-3 == ~2) Console.WriteLine("equal"); else Console.WriteLine("not equal");
output:
equal
In C/C++, the # sign marks preprocessor directives. If you're not familiar with the preprocessor, it works as part of the compilation process, handling includes, macros, and more. It actually adds code to the source file before the final compilation.
@Woot4Moo: snarky can be fun, but in this case it's just dumb. Integral division has very specific rules regarding truncation, and the fact is that 3/2 == 1 . – Matthieu M.
Logical Operators If both the operands are non-zero, then the condition becomes true. (A && B) is false. || Called Logical OR Operator. If any of the two operands is non-zero, then the condition becomes true.
(nk)=n! (n−k)!k! Which means that: (73)=7!
Because two's complement bit-arithmetic makes it so
Cribbed from the wikipedia page and expanded:
Most Significant Bit 6 5 4 3 2 1 0 Value 0 0 0 0 0 0 1 1 3 0 0 0 0 0 0 1 0 2 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 -1 1 1 1 1 1 1 1 0 -2 1 1 1 1 1 1 0 1 -3 1 1 1 1 1 1 0 0 -4
So you get:
0 0 0 0 0 0 1 0 = 2 1 1 1 1 1 1 0 1 = -3
And as you can see, all the bits are flipped, which is what the bitwise NOT operator (~
) does.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With