Lets say I have: (data) mod (polynomial)
1110 0101 mod 1001
I understand that I will need to shift the polynomial to the left most bit of the data and execute a XOR operation.
1110 0101
1001
and i will get a result of
0111 0101
Then I will need the set the polynomial to find the next '1' on the result and move the polynomial to the position and perform the next XOR operation, and repeat the steps until I get the remainder.
So, I understand that I will need to copy my data to an array and using the array I can do a shifting and use a AND operator and compare the first bit of the data with the first bit of the polynomial, if I get a result of '1' and I will then know that I can shift the polynomial to that position.
Here's a snippet of my code:
uint8_t polyarray[4];
uint32_t dataarray[32];
uint64_t mod(int data, int poly, int i) {
memcpy(polyarray, (int[]) {1}, sizeof polyarray);
memcpy(dataarray, (int[]) {1,2,3,4}, sizeof dataarray);
for (i=127; i>=0; i--){
poly << i;
dataarray[4]>>31;
polyarray[1]>>3;
if(dataarray[4] & polyarray[1]=1){
data = data ^ poly;
}
}
I am quite certain that my codes are incomplete but I am not sure where, anyone can help me?
i redo my codes again, will this be better?
void mod(uint8_t i, uint64_t *pPoly, uint64_t *pData)
{
uint64_t Data[128];
uint64_t Poly[4];
for(i=127; i>=0; i--)
{
Poly << i;
pData = &Data[i];
pPoly = &Poly[3];
if (pData = 1)
{
Data = Data^Poly;
}
else
{
Poly>>1;
i--;
}
}
}