Display the bits within a byte. : Bits : Data Type C# Examples


C# Examples » Data Type » Bits »

 

Display the bits within a byte.









    
using  System;  
  
class  Example  {  
    public  static  void  Main()  {  
        int  t;  
        byte  val;    
    
        val  =  123;  
        for(t=128;  t  >  0;  t  =  t/2)  {  
            if((val  &  t)  !=  0)  
                  Console.Write("1  ");    
            if((val  &  t)  ==  0)  
                  Console.Write("0  ");    
        }  
    }  
}
    
   
  
   



Output

0 1 1 1 1 0 1 1


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Data Type
» Bits