【发布时间】:2012-08-27 17:52:13
【问题描述】:
我有一个无符号字符数组[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...
C 中有类似的函数吗? (没有 .net,我使用 KEIL 编译器,因为代码在微控制器上运行)
问候 山姆
【问题讨论】:
-
本网站使用问答格式 - 请不要编辑问题以包含答案。无论如何,您在问题中编辑的答案也是错误的。
标签: c arrays serialization int byte