给定一个可能很大的整数值( C#字符串格式),我希望能够生成它的十六进制等效值。通常的方法不适用于这里,因为我们讨论的是任意大的数字,50位或更多。我所见过的技术使用了这样的技术:
// Store integer 182
int decValue = 182;
// Convert integer 182 as a hex in a string variable
string hexValue = decValue.ToString("X");
// Convert the hex string back to the number
int decAgain = int.Parse(hexValue, System.Globalization.NumberStyles.HexNumber);将不起作用,因为要转换的整数太大。
例如,我需要能够像这样转换字符串:
843370923007003347112437570992242323
转换为它的十六进制等效值。
这些不起作用:
C# convert integer to hex and back again How to convert numbers between hexadecimal and decimal in C#?
发布于 2010-04-16 20:33:35
正如Jens所说,看看Code Project上的BigInt实现。即使他们没有转换成十六进制的函数,只要这个BigInt有一个除法和模运算(我不认为它有一个模数函数,所以你也需要自己写modulo ),你也可以很容易地用write a function自己来做。
https://stackoverflow.com/questions/2652760
复制相似问题