简体   繁体   English

如何将十六进制值转换为biginteger?

[英]how can i convert hexadecimal value to biginteger?

I mean how can I convert my hexadecimal values to biginteger ? 我的意思是如何将十六进制值转换为biginteger?

for example i use this : 例如我用这个:

string value="A1";
BigInteger bi=new BigInteger(value,16);

bi =161; bi = 161; this is true? 这是真的? So how can I convert back it to "A1"? 那么如何将其转换回“ A1”呢?

thanks.. 谢谢..

String.Format supports this: String.Format支持以下功能:

String.Format("0:x", 161);

Working example: 工作示例:

        string value="A1";
        BigInteger bi = BigInteger.Parse(value, NumberStyles.HexNumber);
        string newVal = string.Format("{0:x}", bi);
        //newVal is a1

UPDATE: The above suggestion is valid for the BigInteger implementation in the System.Numerics namespace of .NET 更新:以上建议对.NET的System.Numerics命名空间中的BigInteger实现有效

要将BigInteger转换回十六进制字符串,您可以按照以下方式进行操作:

string value= bi.ToString("X");

ToStringBigInteger被覆盖:

bi.ToString("X")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM