C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 04-13-2008, 11:40 AM   #1
Registered User
 
Join Date: Nov 2007
Posts: 69
checksum sender vs reciever?

Have the written this one program & unsure of how to reverse it so that it will have a sum check for the reciever & then sum check for sender and compare the 2 sum that will return zero.

Code:
/*	Demonstrate the calculation of a checksum using one's
	complement arithmetic.
	   Written by:
	   Date:
*/
#include <stdio.h>
#include <string.h>
#include <pstdint.h>

int main (void)
{
//	Local Declarations
	uint32_t sum      = 0x00000000;
	uint16_t checksum = 0x0000; 

	char*    str      = "ABCDEFGHI";
	int      len;
	int i = 0;

//	Statements
	len = strlen (str);
	if (len % 2  == 1)
	   // Make the number of characters even
	   len++;
	for (i = 0; i < len; i += 2)
	    sum = (sum + str[i] * 256 + str[i + 1]);
	
	// Add carries into lower 16 bits
	while (sum >> 16)
	   sum = (sum & 0xffff) + (sum >> 16);

	// Complement
	checksum = ~sum;

	printf ("str:      %s\n",   str);
	printf ("checksum: %#06X\n", checksum);
	system("Pause");

	return 0;
}	// main

/*	Results:
str:      ABCDEFGHI
checksum: 0XA5EA
Please help.
thank you.
silhoutte75 is offline   Reply With Quote
Old 04-13-2008, 01:27 PM   #2
and the Hat of Guessing
 
tabstop's Avatar
 
Join Date: Nov 2007
Posts: 8,740
If you want a comparison that will return 0 when the two numbers are equal, just use subtraction. I don't know what you're asking with the first part: presumably the sender will calculate the checksum and send it, the receiver will calculate the checksum of what was received and will compare that with the received checksum.
tabstop is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Making of checksum using XOR Subsonics C Programming 4 02-20-2009 01:19 PM
C# and SQL siten0308 C# Programming 2 07-09-2008 12:34 PM
weird checksum function sagitt13 C Programming 7 10-31-2006 01:25 AM
Need help with calculator program Kate C# Programming 1 01-16-2004 10:48 AM


All times are GMT -6. The time now is 03:22 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

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