Uri.FromHex Method (Char)

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets the decimal value of a hexadecimal digit.

Namespace:   System
Assembly:  System (in System.dll)

public static int FromHex(
	char digit
)

Parameters

digit
Type: System.Char

The hexadecimal digit (0-9, a-f, A-F) to convert.

Return Value

Type: System.Int32

An Int32 value that contains a number from 0 to 15 that corresponds to the specified hexadecimal digit.

Exception Condition
ArgumentException

digit is not a valid hexadecimal digit (0-9, a-f, A-F).

The FromHex method converts a character representing a hexadecimal digit (0-9, a-f, A-F) to its decimal value (0 to 15). If digit is not a valid hexadecimal digit, an ArgumentException exception is thrown.

The following example determines whether a character is a hexadecimal character and, if it is, writes the corresponding decimal value to the console.

char  testChar = 'e';
if (Uri.IsHexDigit(testChar) == true)
    Console.WriteLine("'{0}' is the hexadecimal representation of {1}", testChar, Uri.FromHex(testChar));
else 
    Console.WriteLine("'{0}' is not a hexadecimal character", testChar);

string returnString = Uri.HexEscape(testChar);
Console.WriteLine("The hexadecimal value of '{0}' is {1}", testChar, returnString);

.NET Framework
Available since 1.1
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top
Show: