I am trying to simulate the following code in excel, with cells as bits. It would be nice to just line up different rows (Data, FrameCheckSequence, GeneratorPolynomial, etc) and then do the bit operations on the cells (columnwise), shifting until one arrives at the final result. When I do this, however, I don't seem to obtain the desired answer. Trying to figure out why not.
CRC11GenerateFrameCheckSequence
/*
Inputs: ByteArrayPtr is the address of a 13 bit array holding 102 bits of data. The two most significant bits must be 0.
Outputs: 11 bit frame check sequence.
*/
Code:
Extern unsigned short CRC11GenerateFrameCheckSequence( unsigned char * ByteArrayPtr )
{
unsigned short GeneratorPolynomial = 0x0F35;
unsigned short FrameCheckSequence = 0x07FF;
unsigned short Data;
int ByteIndex, Bit;
/* Do most significant byte skipping the 2 most significant bits */
Data = *ByteArrayPtr << 5;
ByteArrayPtr++
for ( Bit = 2; Bit < 8; Bit++ )
{
if ( (FrameCheckSequence ^ Data) & 0x400 )
FrameCheckSequence = (FrameCheckSequence << 1) ^ GeneratorPolynomial;
else
FrameCheckSequence = (FrameCheckSequence << 1);
FrameCheckSequence &= 0x7FF;
Data <<=1;
}
/* Do rest of the bytes */
for ( ByteIndex = 1; ByteIndex < 13; ByteIndex++ )
{
Data = *ByteArrayPtr << 3;
ByteArrayPtr++;
for ( Bit = 0; Bit < 8; Bit++ )
{
if ( (FrameCheckSequence ^ Data) & 0x0400 )
FrameCheckSequence = (FrameCheckSequence << 1) ^ GeneratorPolynomial;
else
FrameCheckSequence = (FrameCheckSequence << 1);
FrameCheckSequence &= 0x7FF;
Data <<=1;
}
}
return FrameCheckSequence;