C Saved Program: kind-terrain

facebook share

Here's the online compiler accompanied with IDE at your service. This is a saved code by one of our users. Try it out or save your own from the IDE page and don't forget to leave a feedback. You can find that at the bottom of the page.


#include <stdio.h>
#include <ctype.h>

int main()
{  
    unsigned int u32crc = 0U;
    unsigned char i = 0;
    unsigned char j = 0;
    unsigned char  u8bit;   
    unsigned char u8DataBuff[8];// = {0x10,0x09,0x10,0x00,0x00,0x00,0xD5,0x00};
    char u8ScanBuff[20];
    const unsigned char *pu8Data;

    pu8Data = &u8DataBuff[0];

    printf("Enter Hex value:\r\n");

    while(i < 7)
    {
            scanf("0%X", u8ScanBuff);
            u8DataBuff[i] = u8ScanBuff[j];
            printf("DataBuffer[%d] = 0x%x\n", i,u8DataBuff[i++]);
    }
    
    if(NULL != pu8Data)    
    {   
        u32crc = 0xFFU;
        
        for ( i = 0U ; i < 7; i++ )
        {
            u32crc ^= pu8Data[i];
            for (u8bit = 0U ; u8bit < 8U ; u8bit++)
            {
                if ((u32crc & 0x80U) != 0U)
                {
                    u32crc <<= 1U;          /* Div by using the Polynomial */
                    u32crc ^= 0x1DU;
                }
                else
                {
                    u32crc <<= 1U;
                }
            }
        }
        u32crc &= 0xFFU;
        u32crc ^= 0xFFU;
    }

    printf("CRC_SAEj1850 = 0x%X",u32crc);
   
    return 0;
}
Execute

Output

Press the execute button or CTRL + enter to run code.

Inputs