bitwise OR

In this chapter you will learn:

  1. Use bitwise OR to make a number odd.

Use bitwise OR to make a number odd.

using System; /*from j a  va 2s  .  c  om*/
 
class Example {  
  public static void Main() { 
    ushort num;  
    ushort i;     
 
    for(i = 1; i <= 10; i++) { 
      num = i; 
 
      Console.WriteLine("num: " + num); 
 
      num = (ushort) (num | 1); // num | 0000 0001 
 
      Console.WriteLine("num after turning on bit zero: " 
                        +  num + "\n");  
    } 
  } 
}

The code above generates the following result.

Next chapter...

What you will learn in the next chapter:

  1. How to use bitwise NOT operator
Home » C# Tutorial » 
C# operators
Arithmetic Operators
Assignment Operator
Remainder operator
Increment operator and decrement operators
Logic operators
Logic operator shortcut
Relational operators
sizeof
Ternary operator(The ? Operator)
typeof
Bitwise Operators
bitwise AND
bitwise OR
bitwise NOT
bitwise exclusive OR
Shift Operators
Precedence of the C# Operators