十进制到HexaDecimal数据转换 [英] Decimal to HexaDecimal Data conversion

查看:116
本文介绍了十进制到HexaDecimal数据转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个25位十进制值,如1011406131533376933715533,我想将其转换为十六进制反之亦然。

请帮帮我..

解决方案





非常大数字,使用 BigInteger (在.NET 4.5,4和.NET 4 Client Profile中支持):

http://msdn.microsoft.com/en-us/library/system.numerics.biginteger.aspx [ ^ ]

  //  添加对System.Numerics.dll的引用,然后在代码文件的顶部添加以下行: 
使用 System.Numerics;



  //  十进制到十六进制: 
BigInteger dec = BigInteger.Parse( 1011406131533376933715533 );
string hex = dec.ToString( X);
Console.WriteLine(hex); // 输出:0D62C6FAE52427AB5DE4D

// 十六进制到十进制:
string hex2 = 0D62C6FAE52427AB5DE4D;
BigInteger dec2 = BigInteger.Parse(hex2,System.Globalization.NumberStyles.HexNumber);
Console.WriteLine(dec2); // 输出:1011406131533376933715533



希望这个帮助


I have A 25 digit decimal values like 1011406131533376933715533 and I want to convert it into Hexadecimal vice verse.
please help me..

解决方案

Hi,

For very large numbers, use a BigInteger (supported in .NET 4.5, 4 and .NET 4 Client Profile):
http://msdn.microsoft.com/en-us/library/system.numerics.biginteger.aspx[^]

// add a reference to System.Numerics.dll, then add this line at the top of your code file:
using System.Numerics;


// decimal to hex:
BigInteger dec = BigInteger.Parse("1011406131533376933715533");
string hex = dec.ToString("X");
Console.WriteLine(hex); // output: 0D62C6FAE52427AB5DE4D

// hex to decimal:
string hex2 = "0D62C6FAE52427AB5DE4D";
BigInteger dec2 = BigInteger.Parse(hex2, System.Globalization.NumberStyles.HexNumber);
Console.WriteLine(dec2); // output: 1011406131533376933715533


Hope this helps.


这篇关于十进制到HexaDecimal数据转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆