1

我需要将十六进制值解析为以 10 为底的长整数。价值类似于:

 9F2EEA4AA03D55B33172E9A86CFF6156AC1628C67983193A337B98995151F9B0F41562290DB98697280E805803E4B18914519CEB55CEA5D03A927C28C36A4BC7

我怎样才能做到这一点?

更新:

在python中,我使用了以下内容:

>> num = "9F2EEA4AA03D55B33172E9A86CFF6156AC1628C67983193A337B98995151F9B0F41562290DB98697280E805803E4B18914519CEB55CEA5D03A927C28C36A4BC7"
>> int(num, 16)
>> 8337103942674051648235321365669510487642415361796636721089378763661406518267124809778145800381557738780272231500412167743930433352841689114003303823985607L

当我的同事尝试@Sergey 的回答时,我的同事得到了不同的结果(负值,而我的不是负值)

>> BigInteger bigInteger = BigInteger.Parse(num, NumberStyles.HexNumber);
>> -5070703987268545451338703632536335639836950458795756656634182680060357511806422167023728497785345688909759626686073883109823449459104880832430345182098489
4

1 回答 1

2

请查看BigInteger Structure以处理大整数。

BigInteger bigInteger = BigInteger.Parse("0D574F480A03D55B33172E9A86CFF6156AC1628C67983193A337B98995151F9B0F41562290DB98697280E805803E4B18914519CEB55CEA5D03A927C28C36A4BC7", NumberStyles.HexNumber);
string s = bigInteger.ToString(); // String with decimal representation.

更新

如果数字应该被解释为正数,即使它的第一个字符是 8-F,在字符串前面加上(开始)0 。请参见上面的示例:0D574...

于 2013-02-06T13:07:02.680 回答