I have a List<bool>
and want to bitwise XOR the list (to create check bits)
here is what I have currently
List<bool> bList = new List<bool>(){true,false,true,true,true,false,false};
bool bResult = bList[0];
for( int i = 1;i< bList.Count;i++)
{
bResult ^= bList[i];
}
Q: Is there a Linq
one-liner to solve this more elegant?
Mixing bitwise and relational operators in the same full expression can be a sign of a logic error in the expression where a logical operator is usually the intended operator.
>> Indicates the bits are to be shifted to the right. Each operand must have an integral or enumeration type. The compiler performs integral promotions on the operands, and then the right operand is converted to type int . The result has the same type as the left operand (after the arithmetic conversions).
A Bitwise And operator is represented as '&' and a logical operator is represented as '&&'. The following are some basic differences between the two operators. a) The logical and operator '&&' expects its operands to be boolean expressions (either 1 or 0) and returns a boolean value.
A bitwise operator in Java is a symbol/notation that performs a specified operation on standalone bits, taken one at a time. It is used to manipulate individual bits of a binary number and can be used with a variety of integer types – char, int, long, short, byte.
bool bResult = bList.Aggregate((a, b) => a ^ b);
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