Thread: comparing 2 different data type..

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    22

    comparing 2 different data type..

    i have a 4byte unsigned char that contain "7b13059c" hex format. this is a part from a 6byte unsigned char data "99887b13059c" which is the checksum for the 2byte "9988" data.

    after i generate a checksum using a function, i got 7b13059c hex checksum that is stored in an unsigned long var.how can i compare it with the checksum in the 4byte unsigned char.

    the situation is something like this :

    Code:
    unsigned char keydata[6];  //keydata will contain "99887b13059c"
    unsigned char key[2];
    unsigned char check_sum[4];
    unsigned long SUM;
    unsigne char skeysat[2];
    
    memcpy(key, keydata, 2);                        //store the "9988" part from the "99887b13059c" in key
    memcpy(check_sum, keydata+2, 4);        //store the "7b13059c" part from the "99887b13059c" in check_sum
    
    checksum(2, key, &SUM) //generate 7b13059c hex checksum n stored in SUM
    
    //if SUM == check_sum ( 7b13059c == "7b13059c" )store key in skeysat
    //else respon invalid checksum
    can anybody help me with this?
    Last edited by nurulhafiz; 09-13-2006 at 10:50 PM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    memcmp() perhaps?
    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.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    22
    thnx again Salem

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Can you check what is wrong with this code
    By Ron in forum C++ Programming
    Replies: 4
    Last Post: 08-01-2008, 10:59 PM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM