如何将一个超大的整数转为十六进制,并能反正转换回来 int value = 753; double temp = Math.Pow(2, value - 1);这样一个超大的整数,怎么转换为十六进制的string,还有反向转换回来。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 string hex = string.Join(" ", BitConverter.GetBytes(temp).Select(x => x.ToString("X").PadLenft(2, '0'))); 只要是整数 int i = 10000; string hexstr = String.Format("{0:X}", i); i = Convert.ToInt32(hexstr, 16); using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1{ class Program { static void Main(string[] args) { int value = 753; double temp = Math.Pow(2, value - 1); Console.WriteLine(temp); string hex = string.Join(" ", BitConverter.GetBytes(temp).Select(x => x.ToString("X").PadLeft(2, '0'))); Console.WriteLine(hex); double t1 = BitConverter.ToDouble(hex.Split(' ').Select(x => Convert.ToByte(x, 16)).ToArray(), 0); Console.WriteLine(t1); } }}2.36895460861314E+22600 00 00 00 00 00 F0 6E2.36895460861314E+226Press any key to continue . . . 主要是这个数已经超出int32了。 using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Numerics;namespace ConsoleApplication1{ class Program { static void Main(string[] args) { BigInteger bi = new BigInteger(2); bi = BigInteger.Pow(bi, 752); byte[] b = bi.ToByteArray(); Console.WriteLine(bi); string hex = string.Join(" ", b.Reverse().Select(x => x.ToString("X").PadLeft(2, '0'))); Console.WriteLine(hex); byte[] b2 = hex.Split(' ').Select(x => Convert.ToByte(x, 16)).Reverse().ToArray(); bi = new BigInteger(b2); Console.WriteLine(bi); } }}2368954608613142296064727002658847893153207423578943803617938290445024036691859262589841322065195431443004960170182911996721771307548239733038768425050630400397422753938064431076454598436887275429173277578302717210224680868249601 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0000 00 00 00 00 00 00 00 00 00 00 00 00 00 0023689546086131422960647270026588478931532074235789438036179382904450240366918592625898413220651954314430049601701829119967217713075482397330387684250506304003974227539380644310764545984368872754291732775783027172102246808682496Press any key to continue . . .引用System.Numerics.dll DbDataadapter更新不了数据库的问题 200分 EXCEL嵌入 form 控件,不一般! winform中,如何取得excel中datetime的day? 关于sql2005!! 伪静态 为何实现不了 也不提示错误!高手指点~ 代码如何设置Anchor C#遍历硬盘 有关C# 中Linq 的一个问题 希望得到大神指点。 开发人员的交流小栈开张啦!希望大家多多支持! 各位帮我看看这问题该如何解决! C#中如何在main函数中实现单例模式 关于C#与S7-200的通讯问题
string hexstr = String.Format("{0:X}", i);
i = Convert.ToInt32(hexstr, 16);
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int value = 753;
double temp = Math.Pow(2, value - 1);
Console.WriteLine(temp);
string hex = string.Join(" ", BitConverter.GetBytes(temp).Select(x => x.ToString("X").PadLeft(2, '0')));
Console.WriteLine(hex);
double t1 = BitConverter.ToDouble(hex.Split(' ').Select(x => Convert.ToByte(x, 16)).ToArray(), 0);
Console.WriteLine(t1);
}
}
}
2.36895460861314E+226
00 00 00 00 00 00 F0 6E
2.36895460861314E+226
Press any key to continue . . .
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
BigInteger bi = new BigInteger(2);
bi = BigInteger.Pow(bi, 752);
byte[] b = bi.ToByteArray();
Console.WriteLine(bi);
string hex = string.Join(" ", b.Reverse().Select(x => x.ToString("X").PadLeft(2, '0')));
Console.WriteLine(hex);
byte[] b2 = hex.Split(' ').Select(x => Convert.ToByte(x, 16)).Reverse().ToArray();
bi = new BigInteger(b2);
Console.WriteLine(bi);
}
}
}
23689546086131422960647270026588478931532074235789438036179382904450240366918592
62589841322065195431443004960170182911996721771307548239733038768425050630400397
4227539380644310764545984368872754291732775783027172102246808682496
01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0
0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
23689546086131422960647270026588478931532074235789438036179382904450240366918592
62589841322065195431443004960170182911996721771307548239733038768425050630400397
4227539380644310764545984368872754291732775783027172102246808682496
Press any key to continue . . .引用System.Numerics.dll