Question:
How to seamlessly converts the integer into a hexadecimal string in C#, and vice versa?Background:
In order to improve the user experience, you can modify the database that stores the user ID as an integer, and display the ID with a shorter value of the hexadecimal equivalent.
Solution:
The key to this conversion is to use the .tring () method provided by INT type.
Our integer to hexades:
To convert the integer into a hexadecimal string, please use the .tring () method with a "X" format description symbol. For example:
This will assign the hexadecimal string "B76" to HEXVALUE.
int intValue = 2934; string hexValue = intValue.ToString("X");
<六> Sixteen -to -Improven:
This will assign an integer 2934 to Intagain.
string hexValue = "B76"; int intAgain = int.Parse(hexValue, System.Globalization.NumberStyles.HexNumber);
For a lowercase hexadecimal number, please use .tring ("X") or .tring ("x4").
The above is the detailed content of How to Convert Integers to Hexadecimal and Back in C#?. For more information, please follow other related articles on the PHP Chinese website!