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代码里的数据有什么关系,不过这种简单的转换用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)就是你想要的距离值