0

I need to take two bytes and OR them together, a rather simple task. However, I do not know the proper syntax to OR the two bytes together.

 byte First = 0x03;
 byte Second = 0x15;

 //Need to or Them
 byte Result = First || Second; //This syntax does not work in C#
Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
tennis779
  • 338
  • 2
  • 6
  • 19
  • Did you read the documentation? You're using the wrong operator. `||` is a *logical* OR. You're looking for `|` which is a bitwise OR. – tnw Aug 19 '14 at 15:17
  • http://stackoverflow.com/questions/1568216/c-sharp-bitwise-or-needs-casting-with-byte-sometimes – Habib Aug 19 '14 at 15:17

2 Answers2

1

You need | Operator

byte Result = (byte)(First | Second);
AlexD
  • 32,156
  • 3
  • 71
  • 65
-1

|| is a logical or not bitwise so you need:

byte Result = (byte) (First | Second);
Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
AnthonyLambert
  • 8,768
  • 4
  • 37
  • 72