Calculation (CRC) not giving expected result???

DanielB33

Active member
Joined
Mar 29, 2013
Messages
40
Programming Experience
1-3
I am calculating CRC for specific MCU. When calculating in C the answer comes out fine. When calculating in vb.net...not correct. See code for vb.net and C below. And one know what is going on??? Why are the two results not the same?
VB.NET:
uint32_t Data = 0x12345678
uint32_t Crc = 0xFFFFFFFF
  int i;
  Crc = Crc ^ Data;
  for(i=0; i<32; i++)
    if (Crc & 0x80000000)
      Crc = (Crc << 1) ^ 0x04C11DB7; // Polynomial used in STM32
    else
      Crc = (Crc << 1);
  return Crc;                                      //Result = 0xDF8A8A2B
}

****VB.NET CODE****
Dim input_data As Uint32 = &H12345678&
Dim POLY As Uint32 = &H4C11DB7&
Dim CRC As Uint32 = &HFFFFFFFF&

CRC = CRC Xor input_data

For count As Integer = 0 To 31
      If (CRC & &H80000000&) Then
           CRC = (CRC << 1) Xor (&H4C11DB7&)
      else
           CRC = CRC << 1
Next
 
Solved. I need to use the And operator rather than the &. That is pretty stupid if you ask me. Any reason for this VB.NET?
 
Ampersand in VB is a concatenation operator. It's much less stupid to use And than all the stupid weird obscure operators in C. For example ^ in VB is a mathematical operator for exponential multiplication, which kinda makes sense. How it ever got to be XOR in C is foreign to me.
 
Back
Top