我有一个unsigned char数组[248]; 填充字节.像2F AF FF 00 EB AB CD EF .....这个阵列是我的字节流,我将来自UART(RS232)的数据存储为缓冲区.
现在我想将字节转换回我的uint16和int32.
在C#中,我使用BitConverter类来执行此操作.例如:
byte[] Array = { 0A, AB, CD, 25 };
int myint1 = BitConverter.ToInt32(bytes, 0);
int myint2 = BitConverter.ToInt32(bytes, 4);
int myint3 = BitConverter.ToInt32(bytes, 8);
int myint4 = BitConverter.ToInt32(bytes, 12);
//...
enter code here
Console.WriteLine("int: {0}", myint1); //output Data...
Run Code Online (Sandbox Code Playgroud)
C中是否有类似的功能?(没有.net,我使用KEIL编译器,因为代码在微控制器上运行)
关心萨姆