Mega Code Archive

 
Categories / C# / Data Types
 

Format byte value to its hexadecimal form

using System; public class Example {    public static void Main()    {         byte[] numbers = { 0, 16, 104, 213 };         foreach (byte number in numbers) {            // Display value with hexadecimal.            Console.Write(number.ToString("X2") + "   ");            // Display value with four hexadecimal digits.            Console.WriteLine(number.ToString("X4"));         }     } }