gpt4 book ai didi

c - BCH -CRC 在 C 中的帮助

转载 作者:太空宇宙 更新时间:2023-11-04 03:42:11 27 4
gpt4 key购买 nike

我正在尝试让 this 在 C 中工作 在 C 中计算 CRC 似乎很容易,但我的 CRC/BCH 例程生成的答案与第一个代码字的链接中的答案不同,即使我尝试手动计算也是如此与链接中给出的内容不匹配。

我的手动计算是

           11101101001    101010011010000010100
111011010010000000000
010001001000000010100
11101101001
01100100001000010100
11101101001
0010010101100010100
11101101001
01111000101010100
11101101001
0001100001110100
11101101001
0010111010000
11101101001
01010111001 ---- remainder (should match with BCH(31,21) value in the link)

我不知道我哪里错了。这是我的代码

int calc_bch_and_parity( int cw_e ) 
{
int bit=0;
int local_cw = 0;
int parity = 0;

local_cw = cw_e;
for( bit=1; bit<=21; bit++, cw_e <<= 1 )
if (cw_e & 0x80000000)
cw_e ^= 0xED200000;

local_cw |= (cw_e >> 21);
cw_e =local_cw;
for( bit=1; bit<=32; bit++, cw_e <<= 1 )
if (cw_e & 0x80000000)
parity++;

return (parity%2) ? local_cw+1 : local_cw;
}

*********************************编辑代码以更清楚地了解流程 ******** ******

 int bit=0;
int local_cw = 0;
int parity = 0;
// int try;
int answer;
// int genpoly = 0x1DA400;
local_cw=cw; /* bch */

for(bit=1; bit<=21; bit++, cw <<= 1)
{
if (cw & 0x80000000)
{
cw ^= 0xED200000;
printf ("mod2 remainder is %x\n", cw);

}

}
printf ("original data is %x\n", local_cw);
local_cw |= (cw >> 21);
printf ("21 bit right shifted remainder is %x\n",cw>>21);

cw =local_cw; /* parity */
for(bit=1; bit<=32; bit++, cw<<=1)
if (cw & 0x80000000) parity++;
{

if(parity%2)
{
printf("codeword is %x \n",local_cw+1 );
answer = local_cw+1;
}
else
{
printf("codeword is %x \n",local_cw );
answer =local_cw;
}
}

return answer;

预期的提醒是1001111100

生物安全信息交易所所的另一个例子。

我尝试过的另一件事是这个 http://www.codeproject.com/Articles/13189/POCSAG-Encoder ,抱歉我必须依赖外部链接,因为我还不能发布图像,在图像的这个链接中你会看到有一个十六进制可见的预编码消息实际的消息是单词“Salam,我设法使用这个预编码的消息成功地将消息传输到寻呼机(将它作为十六进制整数数组馈送到发射机),但即使是这个消息,即“Salam”这个词在编码消息中不可见(至少第一个或最后一个或任何 20 个连续位)。我将整个十六进制消息转换为二进制并将单词“Salam”转换为二进制,并试图找到单词“的前 20 位或后 20 位” Salam”在编码的消息中。现在这对于 CRC(基本上 BCH 是)来说非常奇怪,CRC 不应该编码/扭曲实际消息它应该只是附加余数和奇偶校验(在 BCH 的情况下)。所以实际的消息应该是可见的,前 20 位或后 20 位,我什至尝试改变字节顺序但没有快乐。这是我在这个新示例中所做的努力的详细信息

萨拉姆:01010011 01100001 01101100 01100001 01101101

gx: 10010110111

Salam_reversed_by_byte:11001010 10000110 00110110 10000110 10110110

Salam_rev : 10110110 10000110 00110110 10000110 11001010

1234567 : 00110001001100100011001100110100001101010011011000110111

1234567_reverse :11101100011011001010110000101100110011000100110010001100

Salam 的前 20 位:01010011011000010110 Salam 的 First20_reverse:01101000011011001010

十六进制顺时针:0x4B5A1A25,0xE5866E6E,0x7CD215D8,0xE1DB221B,0x84081630

0x4B5A1A25 : 01001011010110100001101000100101

0xE5866E6E : 11100101100001100110111001101110

0xE1DB221B : 11100001110110110010001000011011

0x84081630 : 10000100000010000001011000110000

最佳答案

对我有用,我所做的就是将红利填充到 32 位

10101001101000001010000000000000
11101101001
01000100100000001010000000000000
11101101001
00110010000100001010000000000000
11101101001
00001001010110001010000000000000
11101101001
00000111100010101010000000000000
11101101001
00000000111000111010000000000000
11101101001
00000000000011101000000000000000
11101101001
00000000000000000101001000000000
11101101001
00000000000000000010010010010000
11101101001
00000000000000000001111111011000
11101101001
00000000000000000000001001111100

这是“手工”计算的代码

#include <stdio.h>
#include <string.h>

char blank[] = " ";
char dividend[] = "10101001101000001010000000000000";
char divisor[] = "11101101001";

int main( void )
{
int i, j;

int N = strlen( dividend );
int M = strlen( divisor );
printf( "%d %d\n", N, M );

for ( i = 0; i < N - M; i++ )
{
if ( dividend[i] == '1' )
{
printf( "%s\n", dividend );
printf( "%s%s\n", &blank[N-i], divisor );
for ( j = 0; j < M; j++ )
{
if ( dividend[i+j] == divisor[j] )
dividend[i+j] = '0';
else
dividend[i+j] = '1';
}
}
}
printf( "%s\n", dividend );
}

还有同样的东西在摆弄位

#include <stdio.h>
#include <stdint.h>

int main( void )
{
uint32_t dividend = 0x153414;
uint32_t generator = 0x769;
uint32_t mask;

dividend <<= 11; // pad the dividend with 11 zeros
generator <<= 21; // left justify the generator
mask = 1 << 31; // start the mask at the MSB
for ( int i = 0; i < 21; i++ )
{
if ( dividend & mask ) // if the dividend has 1 at the current mask position
dividend ^= generator; // "subtract" the generator
generator >>= 1;
mask >>= 1; // move to the next bit
}

printf( "%08x\n", dividend ); // whatever's left is the remainder
}

关于c - BCH -CRC 在 C 中的帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27577404/

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