C#转换整数为十六进制,然后再返回 [英] C# convert integer to hex and back again
问题描述
我如何转换以下?
2934(整数)B76(十六进制)
让我解释什么,我试图做的。我在我的数据库存储为整数用户ID。而不是让用户参考他们的ID我想让他们使用十六进制值。主要的原因是因为它的短。
所以,我不仅需要从整去诅咒,但我还需要从十六进制去整型。
有一个简单的方法在C#这样做吗?
//商店整数182
INT的intValue = 182;
//转换整数182为十六进制的字符串变量
串hexValue = intValue.ToString(X);
//将十六进制字符串回数
INT intAgain = int.Parse(hexValue,System.Globalization.NumberStyles.HexNumber);
从<一个href=\"http://www.geekpedia.com/KB8_How-do-I-convert-from-decimal-to-hex-and-hex-to-decimal.html\">http://www.geekpedia.com/KB8_How-do-I-convert-from-decimal-to-hex-and-hex-to-decimal.html
How can I convert the following?
2934 (integer) to B76 (hex)
Let me explain what I am trying to do. I have User IDs in my database that are stored as integers. Rather than having users reference their IDs I want to let them use the hex value. The main reason is because it's shorter.
So not only do I need to go from integer to hex but I also need to go from hex to integer.
Is there an easy way to do this in C#?
// 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);
from http://www.geekpedia.com/KB8_How-do-I-convert-from-decimal-to-hex-and-hex-to-decimal.html
这篇关于C#转换整数为十六进制,然后再返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!