Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Joel Rainville said:What about ^= and &= ?
:lol:
eblc1388 said:Joel Rainville said:What about ^= and &= ?
:lol:
Both "|=" and "^=" resulted in nothing in Google. "&=" works the same as "&".
(A = A | B) == (A |= B) // inclusive OR
(A = A ^ B) == (A ^= B) // eXclusive OR
(A = A & B) == (A &= B) // AND
Joel Rainville said:The unary NOT operator is !, and of course the != operator isn't a bitwise operator, but a comparison operator meaning "different than"...
eblc1388 said:Joel Rainville said:The unary NOT operator is !, and of course the != operator isn't a bitwise operator, but a comparison operator meaning "different than"...
So "!=" is the XOR instruction in C then?
Programming in CFull guide for ANSI standard C programming language.
www.lysator.liu.se/c/ - 16k - Cached - Similar pages
Brian W. Kernighan: Programming in C: A Tutorial - Yacc
Lex - Why Pascal is Not My Favorite Programming Language
More results from www.lysator.liu.se »
sarang1_in said:It is already mentioned that ! is a unary operator. This means it will only invert 0 to 1 and 1 to 0.
sarang1_in said:eblc1388 said:Joel Rainville said:The unary NOT operator is !, and of course the != operator isn't a bitwise operator, but a comparison operator meaning "different than"...
So "!=" is the XOR instruction in C then?
It is already mentioned that ! is a unary operator. This means it will only invert 0 to 1 and 1 to 0.
But that is true only if the data is in bytes
This means if you write 0XFF != a, then a will contain 0 and if you again invert it by saying !a then the answer will be 1
in binary
!(0000 0000) = (0000 0001)
whereas if you use ~ then it will simply invert each bit as it is a bitwise operator.
NOT operators are unary ie operate on single bit or byte
This means if you write 0XFF != a, then a will contain 0 and if you again invert it by saying !a then the answer will be 1
Joel Rainville said:eblc, the XOR operator in C is ^.
eblc1388 said:But "!=" means "not equal". If A & B are Boolean, then A != B means !(A==B), right?
So is it the same as A XOR B, assuming there is a logical XOR instruction in C?
eblc1388 said:Joel Rainville said:eblc, the XOR operator in C is ^.
Yes, but "^" is a bitwise operator.
If A & B are Boolean, what is A XOR B in C Language? Still A^B ???
Joel Rainville said:Yes... I don't understand why you insist on A & B being boolean though, since it doesn't change anything?
eblc1388 said:Joel Rainville said:Yes... I don't understand why you insist on A & B being boolean though, since it doesn't change anything?
Because they are "states" of something like switches, pin logic level...i.e. condition.
I have a perfectly good reason to test that "Either my switch1 or switch2 is closed but not both" and this needs a XOR test.
So we come back to the original question, can A!=B gives me the required result?
if(i != j)
while(n != p)
i += 1
i = i + 1
a != b can't be
!(a == b) but is
a = !b
sarang1_in said:Bitwise and &
Bytewise and &&
Bitwise or |
Bytewise or ||
Bitwise not ~
Bytewise not !
eblc1388 said:While we can use "&&" to test for both conditions to be true and "||" for either one to be true, I now wonder whether it is legal in C to write:
/* condition1: true/false
condition2: true/false */
If (condition1 != condition2)
{....}
Possible workaround:
If ( (condition1 && !condition2) || (!condition1 && condition2) )
{....}
But it seems too long-winded.