The convenient conversion of integer and hexadecimal value in the c#
How to transform between integer and hexadecimal values in C#? This conversion is necessary for expressing user ID as shorter and more convenient.
Answer:
The integer is converted into hexades
To convert the integer to its hexadecimal representation, please use the Tostring ("X") method. For example:
Sixteen -in -made transition to integer
<code class="language-csharp">int intValue = 2934; string hexValue = intValue.ToString("X"); // 结果:"B76"</code>
Custom:
<code class="language-csharp">string hexValue = "B76"; int intAgain = int.Parse(hexValue, System.Globalization.NumberStyles.HexNumber); // 结果:2934</code>
To get a lowercase hexadecimal number, use Tostring ("X4").
For more conversion numbers (more than 2^32), you can use UINT32 or UINT64 type.
The above is the detailed content of How Can I Efficiently Convert Between Integers and Hexadecimal Values in C#?. For more information, please follow other related articles on the PHP Chinese website!