comparing 2 different data type..

This is a discussion on comparing 2 different data type.. within the C Programming forums, part of the General Programming Boards category; i have a 4byte unsigned char that contain "7b13059c" hex format. this is a part from a 6byte unsigned char ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21