我怎么能转换一个大的十进制数为十六进制在C#(如:588063595292424954445828) [英] How can I Convert a Big decimal number to Hex in C# (Eg : 588063595292424954445828)
本文介绍了我怎么能转换一个大的十进制数为十六进制在C#(如:588063595292424954445828)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在数量上超过大 INT
&安培; 长
,但可以在小数
被accomodated。但正常的的ToString
或转换
方法不要十进制工作
。
The number is bigger than int
& long
but can be accomodated in Decimal
. But the normal ToString
or Convert
methods don't work on Decimal
.
推荐答案
我相信,这将产生它返回任何正确的结果,但可能会拒绝有效整数。我敢说,可以用一点努力,虽然被周围的工作......(哦,它也将失败的时刻负数。)
I believe this will produce the right results where it returns anything, but may reject valid integers. I dare say that can be worked around with a bit of effort though... (Oh, and it will also fail for negative numbers at the moment.)
static string ConvertToHex(decimal d)
{
int[] bits = decimal.GetBits(d);
if (bits[3] != 0) // Sign and exponent
{
throw new ArgumentException();
}
return string.Format("{0:x8}{1:x8}{2:x8}",
(uint)bits[2], (uint)bits[1], (uint)bits[0]);
}
这篇关于我怎么能转换一个大的十进制数为十六进制在C#(如:588063595292424954445828)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文