>> operators : Bitwise Shift : Data Type C# Examples


C# Examples » Data Type » Bitwise Shift »

 

>> operators









    
using  System;  
  
class  Example  {  
    public  static  void  Main()  {  
        int  val  =  128;  
  
        for(int  i  =  0;  i  <  8;  i++)  {    
            for(int  t=128;  t  >  0;  t  =  t/2)  {  
                if((val  &  t)  !=  0)  Console.Write("1  ");    
                if((val  &  t)  ==  0)  Console.Write("0  ");    
            }  
            Console.WriteLine();  
            val  =  val  >>  1;  //  right  shift  
        }  
    }  
}
    
   
  
   



Output

1 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0
0 0 1 0 0 0 0 0
0 0 0 1 0 0 0 0
0 0 0 0 1 0 0 0
0 0 0 0 0 1 0 0
0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 1


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Data Type
» Bitwise Shift