Uri.FromHex Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets the decimal value of a hexadecimal digit.

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

Syntax

'Declaration
Public Shared Function FromHex ( _
    digit As Char _
) As Integer
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.

Exceptions

Exception Condition
ArgumentException

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

Remarks

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.

Examples

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

Dim testChar As Char = "e"
If Uri.IsHexDigit(testChar) = True Then 
  outputBlock.Text &= testChar
  outputBlock.Text &= "is the hexadecimal representation of "
  outputBlock.Text &= Uri.FromHex(testChar)
  outputBlock.Text &= vbCrLf
Else
  outputBlock.Text &= testChar
  outputBlock.Text &= "is not a hexadecimal character"
  outputBlock.Text &= vbCrLf
End If
char  testChar = 'e';
if (Uri.IsHexDigit(testChar) == true) {
    outputBlock.Text += testChar;
    outputBlock.Text += "is the hexadecimal representation of ";
    outputBlock.Text += Uri.FromHex(testChar);
    outputBlock.Text += "\n";
}
else {
    outputBlock.Text += testChar;
    outputBlock.Text += "is not a hexadecimal character\n";
}
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);

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

See Also

Reference