从串口读出 02 03 04 40 49 EB 31 82 01 。
40 49 EB 31 为4个字节的数据。单精度的浮点数。
如何将它转化为 3.15498来显示呢?
byte[] bb = new byte[4]{0x40,0x49,0xEB,0x31};                     
float ff = BitConverter.ToSingle(bb, 0);
结果是6.847728E-09。
怎么弄成 3.15498呢???

解决方案 »

  1.   

    byte[] bb = new byte[4] { 0x40, 0x49, 0xEB, 0x31 };
                Array.Reverse(bb);
                float ff = BitConverter.ToSingle(bb, 0);
      

  2.   


    再问 
    float ff = 3.15498F;
    byte[] bb = BitConverter.GetBytes(ff);
    string s = ToString(bb);输出为00110001111010110100100101000000?
    怎么将3.15498转换为40 49 EB 31?
      

  3.   

    转字符串:BitConverter.ToString(bb).Replace("-"," ");
      

  4.   

    和其他设备通讯时,有时存在顺序问题(内存中也有Far和Near两种结构),对于顺序相反的用Array.Reverse进执行一次反转就可以了.
      

  5.   

    转换为数组形式的。
    bb[0]=0x40;
    bb[1]=0x49;
    bb[2]=0xEB;
    bb[3]=0x31;
      

  6.   

    byte[] bb = BitConverter.GetBytes(ff);
    Array.Reverse(bb);//再来一个反转