IBM BSC CRC?

Peter Coghlan cctalk at beyondthepale.ie
Mon Jan 27 11:13:23 CST 2020


Mattis Lind wrote:
>
> > > I have two actual messages from equipment employing IBM BSC:
> > > 32016CD90240404070032688
> > > and
> > > 32016CD90240C84050030D28
> > >
>

How about this code:

#include <stdio.h>

int crc16(unsigned char *ptr, int count)
{
    unsigned int crc;
    char i;

    crc = 0x0000;
    while (--count >= 0)
    {
        crc = crc ^ (unsigned int) *ptr++;
        i = 8;
        do
        {
            if (crc & 0x0001)
                crc = (crc >> 1) ^ 0xA001;  /* 0x8005 bit reversed */
            else
                crc = (crc >> 1);
        } while(--i);
    }
    return (crc);
}

void main()
{                    
                     /* 32  01  6C  D9  02  40  40  40  70  03  26  88 */

   unsigned char data1[] = {0x6c, 0xd9, 0x02, 0x40, 0x40, 0x40, 0x50, 0x03};

                     /* 32  01  6C  D9  02  40  C8  40  50  03  0D  28 */

   unsigned char data2[] = {0x6c, 0xd9, 0x02, 0x40, 0xc8, 0x40, 0x50, 0x03};

   printf("crc sent: 8826 computed: %4.4x\n", crc16(data1, sizeof(data1)));

   printf("crc sent: 280d computed: %4.4x\n", crc16(data2, sizeof(data2)));

   return;
}

Please note that I had to cheat to get this to work.  It worked initially
for the second case but it only worked for the first case when I tweaked
70 to 50, ie I substituted the corresponding value from the second case.

Regards,
Peter Coghlan.


More information about the cctech mailing list