Question

Goodnight everyone, I´ve been working on this code based on the logic that to obtain a CRC you need to do 2 XOR operations, the first one: result = data ^ generator, then it moves >> bit by bit over the 16 bits and does the XOR over and over again so the crc final is = result ^ generator until it analyzes the whole 32 bit sequence. Generator was a polynome provided by my teacher.

So far this is the code:

{

int dato;       // 16 bits
int polin;      // generador
double r1;      // resultado de la trama de 32 bits


dato = 0x0000000001000100;      
polin = 0x82086DB;     
r1 = dato ^ polin;     // XOR
polin >>= 1;

  while(r1 > 0){
  r1 = dato ^ polin;
  r1 = 0x1 >> dato; 
  }
 printf("%x %x",dato,polin);
 printf("\n\r CRC es: ", r1);
 getch();   
}

My problem is that when I try to execute it, it stays inside the "while" and doesn't provide any result, hope someone can help me.

Was it helpful?

Solution

while(r1 > 0){
   r1 = dato ^ polin;
   r1 = 0x1 >> dato; 
}

Your while loop never exits because the value of r1 never changes after the first iteration. The result of the first line is never used and the second line returns the same result every time because the loop doesn't modify the value of dato.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top