Thread: Checksum generate

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    4

    Question Checksum generate

    Dear all,

    i have the problem with checksum generate array data.
    This is a sample piece of my program
    Code:
    unsigned char data1[3];
    unsigned char data2[4]={0x7F,0xA0,0x00,0x00};
    
    void send(unsigned char *a, unsigned char b, unsigned char *b){
    
    //I do not know what program should i write 
    // in this modular, i want to display result of checksum
    
    }
    
    //main program
    
    //call the modular of send
    send(data1, 0x33, data2); //
    
    //end of main program
    so, how to generate checksum data in modular send?
    i want to generate checksum data from array data1, array data2 and 0x33

    note : i want to use XOR for checksum the data.

    checksum in other words in this case is error detection.
    error detection is generated by "exclusive-OR" all bytes data.

    give me advice

    many thanks
    Last edited by yazixchi; 05-29-2011 at 09:23 PM.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    What is a checksum?


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    May 2011
    Posts
    4
    i mean, error detection.
    error detection is generated by "exclusive-OR" all bytes data.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I mean you have to know what you want to do before you can know how to do it. So, what is your checksum supposed to do?


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    May 2011
    Posts
    4
    Quote Originally Posted by quzah View Post
    I mean you have to know what you want to do before you can know how to do it. So, what is your checksum supposed to do?


    Quzah.
    ok, i want to XOR these all data

    (pseudocode)
    write the data1 value
    data1[0]=0xFF;
    data1[1]=0x0F;
    data1[2]=0xEF;

    checksum=0x33^data1^data2;

    or in manual
    checksum=0x33^(0xFF^0x0F^0xEF)^(0x7F^0xA0^0x00^0x0 0);

  6. #6
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Well... as Quzah is trying to tell you... you can't solve a problem you don't understand...

    Generally a checksum is a 16 or 32 bit value formed by doing some sort of math on one or more bytes of data...
    There are literally hundreds of different ways to do it... The simplest is to simply add everything up... but it gets way more complex than that.

    So... until you understand the problem well enough to explain exactly what you need... there's not much we can do to help you.

  7. #7
    Registered User
    Join Date
    May 2011
    Posts
    4
    i mean, If there is an easier method or better way of doing this I would appreciate any help.
    my problem is accsess the parameter passing

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Are these unsigned char arrays a fixed size? If not, you will need to also pass the size of those arrays into your function, for there is no way for the function to retrieve that data once it starts. After that a big ol' loop with ^= seems indicated.

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > my problem is accsess the parameter passing
    Accessing pointers (to arrays) inside a function uses the same notation as if you had the array itself.
    Code:
    void send(unsigned char *a, unsigned char b, unsigned char *b){
    
    //I do not know what program should i write 
    // in this modular, i want to display result of checksum
        a[0] = 0xFF;
    // or use a for loop to access b[i]
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Calculating CheckSum
    By drkidd22 in forum C++ Programming
    Replies: 10
    Last Post: 01-17-2011, 08:28 PM
  2. crc32/checksum app
    By andwan0 in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2010, 07:45 PM
  3. Making of checksum using XOR
    By Subsonics in forum C Programming
    Replies: 4
    Last Post: 02-20-2009, 01:19 PM
  4. CheckSum help
    By remoir in forum C Programming
    Replies: 13
    Last Post: 02-01-2009, 10:19 PM
  5. CRC / checksum
    By Zoltarc in forum C++ Programming
    Replies: 0
    Last Post: 11-30-2002, 11:05 PM