首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C语言代码翻译成C#该怎么解决

2013-09-29 
C语言代码翻译成C#比如你收到的数据为:FF 55 04 62 00 02 23 8Btypedef union{unsigned int Distancestru

C语言代码翻译成C#

         比如你收到的数据为:FF 55 04 62 00 02 23 8B

             typedef union
             {
                  unsigned int Distance;
                  struct
                 {
                 unsigned char Low;
                 unsigned char Mid1;
                 unsigned char Mid2;
                 unsigned char High;
                  }
             } Distacne_t;



            Distance_t Dist;
            Dist.High = 0x00;
             Dist.Mid2 = 0x00;
             Dist.Mid1 = 0x02;
             Dist.Low = 0x23;
             //Dist.Distance就是你想要的距离值


                }    翻译成C#代码应该是什么?求教 c语言 c#
[解决办法]
没弄清楚你给的数据和C代码里的数据有什么关系,不过这种简单的转换用System.BitConverter就可以

byte[] union = new byte[4];
union[3] = 0x00;//high
union[2] = 0x00;//mid2
union[1] = 0x02;//mid1
union[0] = 0x23;//low
Console.WriteLine(BitConverter.ToInt32(union,0));

BitConverter.ToInt32(union,0)就是你想要的距离值

热点排行