Byte Struct in C#

Byte Struct in C#

 

Represents an 8-bit unsigned integer. The Byte is an immutable value type and the range of Byte is from 0 to 255. In C#, Byte Struct is used to represent 8-bit unsigned integers. the byte type also supports the bitwise ANDORXOR, left shift, and right shift operators.

 

using System; 
  
public class usingcsharp{ 
  
    static public void Main() 
    { 
  
        // val1, val2, and val3 are of byte type 
        byte a1 = 32; 
        byte a2 = 40; 
        byte a3 = 10; 
  
        Console.WriteLine("Comparison 1: {0}", 
                         a1.CompareTo(a2)); 
  
        Console.WriteLine("Comparison 2: {0}",  
                         a2.CompareTo(a3)); 
  
        Console.WriteLine("Comparison 3: {0}",  
                        a3.CompareTo(a3)); 
  
        Console.WriteLine("Comparison 4: {0}", 
                         a.CompareTo(a3)); 
    } 
} 

 

using System; 
  
public class usingcsharp{ 
  
    static public void Main() 
    { 
  
        Console.WriteLine("Minimum value "+ 
                 "of Byte: {0}", Byte.MinValue); 
  
        Console.WriteLine("Maximum value "+ 
                 "of Byte: {0}", Byte.MaxValue); 
    } 
} 

 

byte[] numbers = { 0, 16, 104, 213 };
foreach (byte number in numbers)
{
    Console.Write("{0,-3}  -->   ", number.ToString());
    Console.Write(number.ToString("D3") + "   ");
    Console.Write(number.ToString("X2") + "   ");
    Console.WriteLine(number.ToString("X4"));
}

 

Output

 

0    -->   000   00   0000
16   -->   016   10   0010
104  -->   104   68   0068
213  -->   213   D5   00D5

2021-10-03