G
Guest
I'm trying to set the first three bits to zero on a byte. For some reason,
the compiler is casting the number peculiarly when I use the bitwise
complement operator.
Here's what I think should work but doesn't:
byteArray[6] &= ~0xe0; // set the first three bits to 0 (11100000 == 0xe0)
The error is "Constant value '-225' cannot be converted to a 'byte'".
I've tried several explicit casts, but it seems to only complicate matters
worse. I'd appreciate your suggestions on how to elegantly do this simple
bitwise operation on a byte in C#. (I know...I could do the math in my head
to turn ~0xe0 into 0x1f, but this would make my code less clear in my
opinion.)
the compiler is casting the number peculiarly when I use the bitwise
complement operator.
Here's what I think should work but doesn't:
byteArray[6] &= ~0xe0; // set the first three bits to 0 (11100000 == 0xe0)
The error is "Constant value '-225' cannot be converted to a 'byte'".
I've tried several explicit casts, but it seems to only complicate matters
worse. I'd appreciate your suggestions on how to elegantly do this simple
bitwise operation on a byte in C#. (I know...I could do the math in my head
to turn ~0xe0 into 0x1f, but this would make my code less clear in my
opinion.)