int value = 753;
 double temp = Math.Pow(2, value - 1);
这样一个超大的整数,怎么转换为十六进制的string,还有反向转换回来。

解决方案 »

  1.   

    string hex = string.Join(" ", BitConverter.GetBytes(temp).Select(x => x.ToString("X").PadLenft(2, '0')));
      

  2.   

    只要是整数            int i = 10000;
                string hexstr = String.Format("{0:X}", i);
                i = Convert.ToInt32(hexstr, 16);
      

  3.   

    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+226
    00 00 00 00 00 00 F0 6E
    2.36895460861314E+226
    Press any key to continue . . .
      

  4.   

    主要是这个数已经超出int32了。
      

  5.   

    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);
            }
        }
    }
    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