Parse string in hexadecimal number to byte in CSharp

Description

The following code shows how to parse string in hexadecimal number to byte.

Example


  /*  w w  w.  j av  a 2s.  c om*/
  
  
     

using System;

public class Example
{
   public static void Main()
   {

        string string2 = "A1";
        try {
           byte byte2 = Byte.Parse(string2, System.Globalization.NumberStyles.HexNumber);
           Console.WriteLine(byte2);
        }
        catch (OverflowException) {
           Console.WriteLine("'{0}' is out of range of a byte.", string2);
        }
        catch (FormatException) {
           Console.WriteLine("'{0}' is out of range of a byte.", string2);
        }
    }
}




















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var