![]() |
Calling all Programmers please
I wonder if some could write me a very simple program in any Prog lang you care to - what i need is a program to take a text file - add up all the ascii codes for each char and return a Sum at the end - either in Hex or Dec (prefer Hex)...
Im working on something and trying to work out of this is the method for a check sum there using - ive searched google and not found anything as yet .. |
Re: Calling al Programmers plese
Here's something written in Java, it shows the Hex an Dec values. To run just provide the name of the file you want to scan as the first command line agument, e.g.
java check_sumthing <filename> Note that things like spaces and new line characters count towards the total. Code:
import java.io.*; |
Re: Calling al Programmers plese
|
Re: Calling all Programmers please
I have been beaten to it it seems (damn it, I wrote it so i'll post it at least), but I have knocked up something quick and dirty (in C) here:
Code:
#include <stdio.h>checksum filename If you need me to add more comments in it, or explain anything, let me know. It needs a bit more work (check there is a parameter in the command line), but it does the job. The psuedo-code is more or less the same, which is why it looks so close to Phil's version. Basically: 1. Open a file 2. Read one character at a time until you get a null value/error 3. Add the ascii value (normally cast character to an integer) to a cumlative value 4. format and display the integer as a hexadecimal value. HTH |
Re: Calling all Programmers please
I prefer to keep it simple
function CheckSum(str) { var sum; sum=0; i = 0 while (i<str.length) { sum = sum + str.charCodeAt(i); i=i+1; } return sum; } charCodeAt(i); is just teh javascript equiv of basic mid() and asc() |
Re: Calling all Programmers please
Many thanks for the files/info - Ill give them a Try and see if i can crack this damm checksum thing - its uses 8 numbers and is not time / date or file size based which is why i thought sum total of all the ascii - :)
|
| All times are GMT. The time now is 19:02. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
All Posts and Content are © Cable Forum