我有一个一定大小的字节数组。我想抓住它的最后四个字节并将它们彼此相邻以在变量中形成一个四字节十六进制值。这样我就可以将一个四字节的 CRC-32 值与我的变量进行比较,并检查 CRC 值是否相同。现在这就是我目前这样做的方式:
static unsigned long whole_four = 0; // This variable holds the last four bytes of the received bytes which are the CRC bytes
//Note that "MAX_INPUT" is the size of my array and "data" is just a pointer I have used as an argument to a function to point to the elements a buffer array.
whole_four = ((unsigned long)(*(data+(MAX_INPUT-4)))<< 24) | ((unsigned long)(*(data+(MAX_INPUT-3)))<< 16) | ((unsigned long)(*(data+(MAX_INPUT-2)))<< 8) | ((unsigned long)(*(data+(MAX_INPUT-1))));
所以你可以看到我正在移动和“或”我数组的最后四个元素以创建一个四字节变量。现在,我的问题是:有没有更快的方法来实现这一点并减少所需的处理能力?我还想提一下,我正在 Arduino Uno 上编译此代码。非常感谢任何帮助或提示。