How to convert numbers between hexadecimal and decimal in C#?
你如何转换C#中的十六进制数字和十进制数字?
To convert from decimal to hex do...
string hexValue = decValue.ToString("X");
To convert from hex to decimal do either...
int decValue = int.Parse(hexValue, System.Globalization.NumberStyles.HexNumber);
or
int decValue = Convert.ToInt32(hexValue, 16);
Hex -> decimal:
Convert.ToInt64(hexValue, 16);
Decimal -> Hex
string.format("{0:x}", decValue);
It looks like you can say
Convert.ToInt64(value, 16)
to get the decimal from hexdecimal.
The other way around is:
otherVar.ToString("X");
链接地址: http://www.djcxy.com/p/89826.html