-1

I have data of 18005 hexadecimal frames, and I want to calculate crc-16(0xffff) of all frames simultaneously and then append.

Racil Hilan
  • 24,690
  • 13
  • 50
  • 55
  • 1
    Welcome to Stack Overflow! Questions asking for completed code are not on-topic for StackOverflow. You haven't even specified the language that you wish to use, so there's no hope of anyone being able to answer this question usefully as it stands. – Aurora0001 Oct 16 '16 at 19:49
  • I use c# language – owais rasheed Oct 16 '16 at 20:08

1 Answers1

1

Your CRC is not adequately specified. Are you trying to be compatible with some protocol that uses a 16-bit CRC? If so, you need to find out the parameters of that CRC. You can find here a list of 28 different 16-bit CRC definitions. The one you need might be one of those, or it might be yet another set of parameters.

It is not at all clear what the "(0xffff)" means in your name. The initial value? The final exclusive-or? The CRC of an empty string? Something else?

It is not clear what you mean by calculating the CRC of all frames "simultaneously". Why did you say simultaneously?

When appending the CRC, you will also need to know the bit or byte-order in which it should be appended. A two-byte CRC could be appended in little or big-endian order.

Update:

From the example CRCs in the comments, the desired CRC-16 is CRC-16/CCITT-FALSE from the RevEng catalog. You can use crcany to generate C code that computes this CRC. It will generate bit-wise, byte-wise, and word-wise code, at varying levels of speed and complexity. The bit-wise routine generated is:

#include <stdint.h>

unsigned crc16ccitt_false_bit(unsigned crc, void const *data, size_t len) {
    if (data == NULL)
        return 0xffff;
    while (len--) {
        crc ^= (unsigned)(*(unsigned char const *)data++) << 8;
        for (unsigned k = 0; k < 8; k++)
            crc = crc & 0x8000 ? (crc << 1) ^ 0x1021 : crc << 1;
    }
    crc &= 0xffff;
    return crc;
}

(When buf is NULL, the initial CRC value is returned.)

You can tell by inspection from your example streams if the CRC is appended in little or big-endian order.

Mark Adler
  • 101,978
  • 13
  • 118
  • 158
  • Sir,I have data in which there are 18005 hexadecimal frames. One sample Frame is given as: – owais rasheed Oct 17 '16 at 19:31
  • "AA01004AFF025773429200000000014048A76F64BE211C4648A76F64C0101C5648A76F64C08B137444154CBDBFA2073444154CBDC0570E2C44154CBDC0AE8C5F42700000B48B4296" – owais rasheed Oct 17 '16 at 19:32
  • Above is my sample frame. I have 18004 more frames like this and i have to calculate and append crc-16 bit to all frames (at the end of frame) simultaneously. My each frame size is of 72 Bytes and i have to append two more bytes of crc which has initial value of 0xFFFF? – owais rasheed Oct 17 '16 at 19:35
  • There are many possible CRC-16's. Which one? Do you have an example of a frame with a correct CRC? – Mark Adler Oct 17 '16 at 21:14
  • This is my sample frame : "AA01004AFF025773429200000000014048A76F64BE211C4648A76F64C0101C5648A76F64C08B137444154CBDBFA2073444154CBDC0570E2C44154CBDC0AE8C5F42700000B48B4296" . Its correct crc ans is C2F0. This crc is referred by this website : ammertbies.nl/comm/info/crc-calculation.html – owais rasheed Oct 18 '16 at 13:01
  • Another frame is : "AA01004AFF025773429200002710014048A76F65BE211C4448A76F65C0101C5648A76F65C08B137444154CBDBFA2073444154CBDC0570E2C44154CBDC0AE8C5F42700000349633DB" . Its crc answer is 9694. These crc ans are in hexadecimal mode. – owais rasheed Oct 18 '16 at 13:03
  • website is lammertbies.nl/comm/info/crc-calculation.html – owais rasheed Oct 18 '16 at 14:13
  • Sir can you give an example how i insert *data in above function ? – owais rasheed Oct 19 '16 at 13:59
  • I have to append crc in big endian order – owais rasheed Oct 19 '16 at 14:01