What is the sentence mean?Thanks

Discussion in 'C Programming' started by yezi, Nov 28, 2005.

  1. yezi

    yezi Guest

    Hi, All:

    I am reading the following code:

    unsigned long crcbitbybitfast(unsigned char* p, unsigned long len) {

    // fast bit by bit algorithm without augmented zero bytes.
    // does not use lookup table, suited for polynom orders between
    1...32.

    unsigned long i, j, c, bit;
    unsigned long crc = crcinit_direct;

    for (i=0; i<len; i++) {

    c = (unsigned long)*p++;

    for (j=0x80; j; j>>=1) {

    bit = crc & crchighbit;
    crc<<= 1;
    if (c & j) bit^= crchighbit;
    if (bit) crc^= polynom;
    }
    }

    if (refout) crc=reflect(crc, order);
    crc^= crcxor;
    crc&= crcmask;

    return(crc);
    }

    bit^= crchighbit; what is that mean?

    Thanks for any clue.


    bin YE
    yezi, Nov 28, 2005
    #1
    1. Advertising

  2. yezi

    pemo Guest

    "yezi" <> wrote in message
    news:...
    > Hi, All:
    >
    > I am reading the following code:
    >
    > unsigned long crcbitbybitfast(unsigned char* p, unsigned long len) {
    >
    > // fast bit by bit algorithm without augmented zero bytes.
    > // does not use lookup table, suited for polynom orders between
    > 1...32.
    >
    > unsigned long i, j, c, bit;
    > unsigned long crc = crcinit_direct;
    >
    > for (i=0; i<len; i++) {
    >
    > c = (unsigned long)*p++;
    >
    > for (j=0x80; j; j>>=1) {
    >
    > bit = crc & crchighbit;
    > crc<<= 1;
    > if (c & j) bit^= crchighbit;
    > if (bit) crc^= polynom;
    > }
    > }
    >
    > if (refout) crc=reflect(crc, order);
    > crc^= crcxor;
    > crc&= crcmask;
    >
    > return(crc);
    > }
    >



    > bit^= crchighbit; what is that mean?


    it means:

    bit = bit ^ crchighbit

    ^ means bitwise XOr
    pemo, Nov 28, 2005
    #2
    1. Advertising

  3. yezi <> wrote:

    > bit^= crchighbit; what is that mean?


    bit=bit^crchighbit; /* where ^ is XOR operator */

    Your friendly C reference has more information.

    --
    Christopher Benson-Manica | I *should* know what I'm talking about - if I
    ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
    Christopher Benson-Manica, Nov 28, 2005
    #3
  4. yezi

    pemo Guest

    "pemo" <> wrote in message
    news:dmfeqi$smk$...
    >
    > "yezi" <> wrote in message
    > news:...
    >> Hi, All:
    >>
    >> I am reading the following code:
    >>
    >> unsigned long crcbitbybitfast(unsigned char* p, unsigned long len) {
    >>
    >> // fast bit by bit algorithm without augmented zero bytes.
    >> // does not use lookup table, suited for polynom orders between
    >> 1...32.
    >>
    >> unsigned long i, j, c, bit;
    >> unsigned long crc = crcinit_direct;
    >>
    >> for (i=0; i<len; i++) {
    >>
    >> c = (unsigned long)*p++;
    >>
    >> for (j=0x80; j; j>>=1) {
    >>
    >> bit = crc & crchighbit;
    >> crc<<= 1;
    >> if (c & j) bit^= crchighbit;
    >> if (bit) crc^= polynom;
    >> }
    >> }
    >>
    >> if (refout) crc=reflect(crc, order);
    >> crc^= crcxor;
    >> crc&= crcmask;
    >>
    >> return(crc);
    >> }
    >>

    >
    >
    >> bit^= crchighbit; what is that mean?

    >
    > it means:
    >
    > bit = bit ^ crchighbit
    >
    > ^ means bitwise XOr


    Of course, you can turn it into a logical(ish) operator via: !! e.g.,

    bit = !!bit ^ !!crchighbit
    pemo, Nov 28, 2005
    #4
    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. Jluis
    Replies:
    3
    Views:
    688
    Riyaz
    May 5, 2004
  2. Geo
    Replies:
    0
    Views:
    466
  3. Geo
    Replies:
    6
    Views:
    517
  4. yezi

    Can I use that sentence ? Thanks

    yezi, Nov 4, 2005, in forum: C Programming
    Replies:
    10
    Views:
    514
    Simon Biber
    Nov 17, 2005
  5. C Barrington-Leigh
    Replies:
    1
    Views:
    1,178
    Tim Leslie
    Sep 10, 2010
Loading...

Share This Page