CRC calculation

Discussion in 'C Programming' started by ALuPin, Jul 2, 2004.

  1. ALuPin

    ALuPin Guest

    Hi,

    I have found a piece of C code for checksum calculation
    CRC16 ccitt.

    Is that right?
    How can I initialize crc?




    #include <stdio.h>

    int crc_1021(int data)
    {

    int x;

    x = ((crc>>8) ^ data) & 0xff;
    x ^= x>>4;
    crc = (crc << 8) ^ (x << 12) ^ (x <<5) ^ x;
    crc &= 0xffff;

    return(crc);

    }

    int main()

    {
    int crc
    printf("The CRC16-X25_ccitt of %d is %d. \n", crc, crc_1021(crc));
    return 0;
    }
     
    ALuPin, Jul 2, 2004
    #1
    1. Advertising

  2. ALuPin

    Grumble Guest

    ALuPin wrote:

    > I have found a piece of C code for checksum calculation
    > CRC16 ccitt.
    >
    > Is that right?
    > How can I initialize crc?


    Errr. Where is your question about the C language?
     
    Grumble, Jul 2, 2004
    #2
    1. Advertising

  3. ALuPin

    Jack Klein Guest

    On 2 Jul 2004 04:23:19 -0700, (ALuPin) wrote in
    comp.lang.c:

    > Hi,
    >
    > I have found a piece of C code for checksum calculation
    > CRC16 ccitt.
    >
    > Is that right?
    > How can I initialize crc?
    >
    >
    >
    >
    > #include <stdio.h>
    >
    > int crc_1021(int data)
    > {
    >
    > int x;
    >
    > x = ((crc>>8) ^ data) & 0xff;
    > x ^= x>>4;
    > crc = (crc << 8) ^ (x << 12) ^ (x <<5) ^ x;
    > crc &= 0xffff;
    >
    > return(crc);
    >
    > }
    >
    > int main()
    >
    > {
    > int crc


    Change the line above to:

    int crc = /* whatever initial value you want */

    > printf("The CRC16-X25_ccitt of %d is %d. \n", crc, crc_1021(crc));
    > return 0;
    > }


    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++
    http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
     
    Jack Klein, Jul 4, 2004
    #3
  4. ALuPin

    ALuPin Guest

    Grumble <> wrote in message news:<cc3jm3$191$>...
    > ALuPin wrote:
    >
    > > I have found a piece of C code for checksum calculation
    > > CRC16 ccitt.
    > >
    > > Is that right?
    > > How can I initialize crc?

    >
    > Errr. Where is your question about the C language?


    Hey,

    if you do not want to help then SHUT UP.

    Thank you very much.

    Best regards
     
    ALuPin, Jul 5, 2004
    #4
  5. ALuPin

    xarax Guest

    "ALuPin" <> wrote in message
    news:...
    > Grumble <> wrote in message news:<cc3jm3$191$>...
    > > ALuPin wrote:
    > >
    > > > I have found a piece of C code for checksum calculation
    > > > CRC16 ccitt.
    > > >
    > > > Is that right?
    > > > How can I initialize crc?

    > >
    > > Errr. Where is your question about the C language?

    >
    > Hey,
    >
    > if you do not want to help then SHUT UP.
    >
    > Thank you very much.
    >
    > Best regards


    You are posting your question in the wrong
    group, so please take your own advice.
     
    xarax, Jul 5, 2004
    #5
  6. On 5 Jul 2004 00:07:31 -0700, in comp.lang.c , (ALuPin)
    wrote:

    >Grumble <> wrote in message news:<cc3jm3$191$>...


    >> Errr. Where is your question about the C language?

    >
    >if you do not want to help then SHUT UP.


    You ask an offtopic question, get asked what your actual relevant question
    is, and are rude? Thats very silly.

    >Thank you very much.


    Welcome.
    --
    Mark McIntyre
    CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
    CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>


    ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
    http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
    ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---


    ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
    http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
    ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
     
    Mark McIntyre, Jul 5, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Runar Gjelsvik

    CRC polynomal calculation

    Runar Gjelsvik, Apr 28, 2004, in forum: VHDL
    Replies:
    2
    Views:
    2,301
    Allan Herriman
    Apr 29, 2004
  2. CRC calculation

    , Feb 16, 2007, in forum: VHDL
    Replies:
    4
    Views:
    1,001
    Marcus Harnisch
    Feb 26, 2007
  3. Mamut

    crc-8 and crc-16 code...

    Mamut, Feb 21, 2007, in forum: C++
    Replies:
    5
    Views:
    4,066
    Victor Bazarov
    Feb 22, 2007
  4. `Zidane Tribal
    Replies:
    1
    Views:
    2,522
    Joe Smith
    Jul 28, 2007
  5. `Zidane Tribal
    Replies:
    3
    Views:
    259
    Sisyphus
    Jul 27, 2007
Loading...

Share This Page