gpt4 book ai didi

c - 将字节数组传递给函数

转载 作者:太空宇宙 更新时间:2023-11-04 06:41:36 26 4
gpt4 key购买 nike

我为这个问题道歉(完全是新手),USPS 网站上有以下功能可用于生成条形码。文档显示了这一点:USPS_MSB_Math_CRC11GenerateFrameCheckSequence(016907B2A24ABC16A2E5C004B1(HEX)) = 751(HEX)

我已经尝试了很多事情(传递十六进制、将 0x 放在前面、传递二进制)但我可以获得正确的结果,我应该如何将十六进制值传递给函数?任何想法/建议/更正请......非常非常感谢!

/*Inputs: ByteArrayPtr is the address of a 13 byte array holding 102 bits which
are right justified - ie: the leftmost 2 bits of the first byte do not
hold data and must be set to zero.

Outputs: Outputs:return unsigned short - 11 bit Frame Check Sequence (right justified)
*/

extern unsigned short
USPS_MSB_Math_CRC11GenerateFrameCheckSequence( unsigned char *ByteArrayPtr )
{
unsigned short GeneratorPolynomial = 0x0F35;
unsigned short FrameCheckSequence = 0x07FF;
unsigned short Data;
int ByteIndex,Bit;

/* Do most significant byte skipping the 2 most significant bits */
Data = *ByteArrayPtr << 5;
ByteArrayPtr++;

for ( Bit = 2; Bit < 8; Bit++ ) {
if ( (FrameCheckSequence ^ Data) & 0x400 )
FrameCheckSequence = (FrameCheckSequence << 1) ^ GeneratorPolynomial;
else
FrameCheckSequence = (FrameCheckSequence << 1);
FrameCheckSequence &= 0x7FF;
Data <<= 1;
}

/* Do rest of the bytes */
for ( ByteIndex = 1; ByteIndex < 13; ByteIndex++ ) {
Data = *ByteArrayPtr << 3;
ByteArrayPtr++;
for ( Bit = 0; Bit < 8; Bit++ ) {
if ( (FrameCheckSequence ^ Data) & 0x0400 )
FrameCheckSequence = (FrameCheckSequence << 1) ^ GeneratorPolynomial;
else
FrameCheckSequence = (FrameCheckSequence << 1);

FrameCheckSequence &= 0x7FF;
Data <<= 1;
}
}

return FrameCheckSequence;
}

最佳答案

您应该创建一个数组,然后将其传入 - 就像顶部的评论所说的那样。

以你的例子为例:

unsigned char array[] = { 0x01, 0x69, 0x07, 0xB2, 0xA2, 0x4A, 0xBC, 
0x16, 0xA2, 0xE5, 0xC0, 0x04, 0xB1
};
unsigned short myCRC = USPS_MSB_Math_CRC11GenerateFrameCheckSequence(array);

关于c - 将字节数组传递给函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7324289/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com