📄 pnseed.c
字号:
/*****************************************************************
* Generic PN code shifter
* This program calculates Linear Feedback Shift Register(LFSR)
* mask and seed values for a specific phase shift.
* Platform: Any gcc platform
* Date: 12d/05m/00y
*****************************************************************/
#include <stdio.h>
#include <string.h>
/*
* Return true when the tested bit position contains binary 1;
* otherwise return false.
*/
int testbit(long long number, int bitnum)
{
return (int) ((number >> bitnum) & 1LL);
}
/*
* Modify the specified bit position to the provided binary value;
* return the resulted value.
*/
long long setbit(long long number, int bitnum, int set)
{
return (number & (~(1LL << bitnum))) | ((long long)set << bitnum);
}
/*
* Perform multiplication in Galois Field,
* return the result.
*/
long long multi(long long poly, long long op1, long long op2)
{
long long result;
int i,n;
n = sizeof(long long)*8-1;
for (i=0; i<sizeof(long long)*8-1; i++)
{
if (((poly >> n) & 1LL) == 1LL)
{
break;
}
n--;
}
if (n==0)
{
return 0LL;
}
result = 0;
for(i=0; i<n; i++)
{
if (testbit(op1,i) == 1)
{
result ^= op2;
}
op2 <<= 1;
if (testbit(op2,n) == 1)
{
op2 ^= poly;
}
}
return result;
}
/*
* convolve with 憁atrix A
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -