Outils pour utilisateurs

Outils du site


lang:csharp:nombres

Conversion d'un nombre entier en hexadécimal et inversement

// Store integer 182
int intValue = 182;
// Convert integer 182 as a hex in a string variable
string hexValue = intValue.ToString("X");
// Convert the hex string back to the number
int intAgain = int.Parse(hexValue, System.Globalization.NumberStyles.HexNumber);

How do I convert from decimal to hex and hex to decimal? (C# Knowledge Base) • Geekpedia, Archive

Utiliser des nombres en représentation binaire

On ne peut pas encore (c#7 peut-être). Une alternative : Convert.ToInt32(“1000111001”, 2);

Convertir un nombre en texte conformément à un format

15.ToString("000");

Et pour forcer l'affichage des signes, il faut utiliser un pattern. Le premier est le format si le nombre est positif, le second si le nombre est négatif, le troisième est si le nombre est nul.

15.ToString("+000;-000;+000");
lang/csharp/nombres.txt · Dernière modification : 2017/09/09 14:44 de root