int A = 997214237;
            //得到 B(0)=1D B(1)=48 B(2)= 70 B(3)=3B
            byte[] B = System.BitConverter.GetBytes(A);
            //将数组倒序得到 B(0)=3B B(1)=70 B(2)= 48 B(3)=1D
            System.Array.Reverse(B);            byte[] C = new byte[] { 0x3b, 0x70, 0x48, 0x1d };
            //将数组倒序得到C(0)=1D C(1)=48 C(2)= 70 C(3)=3B
            System.Array.Reverse(C);
            //得到整数D= 997214237;
            int D = System.BitConverter.ToInt32(C, 0);

解决方案 »

  1.   

     // 方法1
            int a = 997214237;
            byte[] B = new byte[4];
            string str = Convert.ToString(a, 16);
            if (str.Length % 2 == 1)
                str = "0" + str;
            int index = 0;
            for (int i = 0; i < str.Length; i += 2)
            {
                B[index++] = Convert.ToByte(str.Substring(i, 2), 16);
            }        System.Text.StringBuilder sb = new System.Text.StringBuilder();
            for (int i = 0; i < 4; i++)
            {
                sb.Append(Convert.ToString(B[3 - i], 16));
            }
            a = Convert.ToInt32(sb.ToString(), 16);        // 方法2
            int a = 997214237;
            IntPtr pa =  Marshal.AllocHGlobal(4);
            Marshal.WriteInt32(pa,a);        byte[] B = new byte[4];
            for (int i = 0; i < 4; i++)
            {
                B[i] = Marshal.ReadByte(pa, 3-i);
            }        for (int i = 0; i < 4; i++)
            {
                Marshal.WriteByte(pa, i, B[i]);
            }
            a = Marshal.ReadInt32(pa);        Marshal.FreeHGlobal(pa);
      

  2.   


    /*
    思想如下四个byte
    00000000 00000000 00000000 11111111
    &
    10101010 01011001 01011001 10101101
    */
    int A=997214237;
    byte[] B=new byte[6];
    B[1]=A&0xFF000000>>(8*3);
    B[2]=A&0xFF0000>>(8*2);
    B[3]=A&0xFF00>>(8*1);
    B[4]=A&0xFF>>(8*0);//反过来
    A=(B[1]<<(8*3))|(B[2]<<(8*2))|(B[3]<<(8*1))|B[4]