Use bitwise AND to make a number even : Operator bitwise : Language Basics C# Source Code


Custom Search

C# Source Code » Language Basics » Operator bitwise »

 

Use bitwise AND to make a number even









    

/*
C#: The Complete Reference 
by Herbert Schildt 

Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/

//  Use bitwise AND to make a number even. 
using System; 
 
public class MakeEven {  
  public static void Main() { 
    ushort num;  
    ushort i;     
 
    for(i = 1; i <= 10; i++) { 
      num = i; 
 
      Console.WriteLine("num: " + num); 
 
      num = (ushort) (num & 0xFFFE); // num & 1111 1110 
 
      Console.WriteLine("num after turning off bit zero: " 
                        +  num + "\n");  
    } 
  } 
}


           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Language Basics
» Operator bitwise