The shift << operators : Bitwise Shift « Data Type « C# / CSharp Tutorial






using System; 
 
class Example { 
  public static void Main() { 
    int val = 1; 
 
    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; // left shift 
    } 
    Console.WriteLine(); 
 
  } 
}
0 0 0 0 0 0 0 1
0 0 0 0 0 0 1 0
0 0 0 0 0 1 0 0
0 0 0 0 1 0 0 0
0 0 0 1 0 0 0 0
0 0 1 0 0 0 0 0
0 1 0 0 0 0 0 0
1 0 0 0 0 0 0 0








2.46.Bitwise Shift
2.46.1.The shift << operators
2.46.2.>> operators
2.46.3.Use the shift operators to multiply and divide by 2
2.46.4.left shift
2.46.5.right shift