Leer en inglés

Compartir a través de


Uri.FromHex(Char) Método

Definición

Obtiene el valor decimal de un dígito hexadecimal.

C#
public static int FromHex(char digit);

Parámetros

digit
Char

Dígito hexadecimal (0-9, a-f, A-F) que se va a convertir.

Devoluciones

Número comprendido entre 0 y 15 que corresponde al dígito hexadecimal especificado.

Excepciones

digit no es un dígito hexadecimal válido (0 a 9, "a" a "f", "A" a "F").

Ejemplos

En el ejemplo siguiente se determina si un carácter es un carácter hexadecimal y, si es así, escribe el valor decimal correspondiente en la consola.

C#
char  testChar = 'e';
if (Uri.IsHexDigit(testChar))
    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);

Comentarios

El FromHex método convierte un carácter que representa un dígito hexadecimal (0-9, a-f, A-F) en su valor decimal (de 0 a 15). Si digit no es un dígito hexadecimal válido, se produce una ArgumentException excepción.

Se aplica a

Producto Versiones
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1