Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

checksum

checksum

2007-03-13 by magzky02

i would like to get the sum of values of characters in a string. I 
use to get the checksum.

ex.
strcopy(string1, "abcdefghigklmnopqrstuvwxyz");

this does not work:

sum=0;
for (i = 0; i < strlen(string1); i++)
{
sum = sum + string[i];
}

but this works:

sum = string1[0] + string1[1] + .... + string[25];

but is too lengthy to do the later method.
is there any shorter method to get the sum of values in a string? 

regards

mago

Re: [AVR-Chat] checksum

2007-03-13 by Jim Wagner

Have you checked the exection of the "for" loop in the
debugger?

Jim


On 12 Mar 2007 22:10:47 -0700,Tue, 13 Mar 2007 05:10:11
-0000
 "magzky02" <magzky02@yahoo.com> wrote:
> i would like to get the sum of values of characters in a
> string. I 
> use to get the checksum.
> 
> ex.
> strcopy(string1, "abcdefghigklmnopqrstuvwxyz");
> 
> this does not work:
> 
> sum=0;
> for (i = 0; i < strlen(string1); i++)
> {
> sum = sum + string[i];
> }
> 
> but this works:
> 
> sum = string1[0] + string1[1] + .... + string[25];
> 
> but is too lengthy to do the later method.
> is there any shorter method to get the sum of values in a
> string? 
> 
> regards
> 
> mago
> 

---------------------------------------------------------------
The Think Different Store
http://www.thinkdifferentstore.com/
For All Your Mac Gear
---------------------------------------------------------------

Re: [AVR-Chat] checksum

2007-03-13 by mago Umandam

Good idea... i checked the execution and of the for loop and it didnt go with the summation.  i checked again my for loop statement and i see a misplaced semicolon though far but was not commented out... HUHh... thus doing nothing on for loop:D
   
  thanks
   
  mago

Jim Wagner <jim_d_wagner@applelinks.net> wrote:
          Have you checked the exection of the "for" loop in the
debugger?

Jim

On 12 Mar 2007 22:10:47 -0700,Tue, 13 Mar 2007 05:10:11
-0000
"magzky02" <magzky02@yahoo.com> wrote:
> i would like to get the sum of values of characters in a
> string. I 
> use to get the checksum.
> 
> ex.
> strcopy(string1, "abcdefghigklmnopqrstuvwxyz");
> 
> this does not work:
> 
> sum=0;
> for (i = 0; i < strlen(string1); i++)
> {
> sum = sum + string[i];
> }
> 
> but this works:
> 
> sum = string1[0] + string1[1] + .... + string[25];
> 
> but is too lengthy to do the later method.
> is there any shorter method to get the sum of values in a
> string? 
> 
> regards
> 
> mago
> 

----------------------------------------------------------
The Think Different Store
http://www.thinkdifferentstore.com/
For All Your Mac Gear
----------------------------------------------------------


         

 
---------------------------------
Need Mail bonding?
Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users.

[Non-text portions of this message have been removed]

Re: [AVR-Chat] checksum

2007-03-13 by John Samperi

At 04:10 PM 13/03/2007, you wrote:
>i would like to get the sum of values of characters in a string.

Are you just going to sum all the values of the characters or will
you need something a bit more robust like CRC16?


Regards

John Samperi

********************************************************
Ampertronics Pty. Ltd.
11 Brokenwood Place Baulkham Hills, NSW 2153 AUSTRALIA
Tel. (02) 9674-6495       Fax (02) 9674-8745
Email: john@ampertronics.com.au
Website  http://www.ampertronics.com.au
*Electronic Design * Custom Products * Contract Assembly
********************************************************

Re: [AVR-Chat] checksum

2007-03-13 by mago Umandam

Good you mention about CRC. for now, i just get the sum and 2's compliment. But i look forward on doing CRC in the future. never did that yet :)
   
  regards
   
  mago

John Samperi <samperi@ampertronics.com.au> wrote:
          At 04:10 PM 13/03/2007, you wrote:
>i would like to get the sum of values of characters in a string.

Are you just going to sum all the values of the characters or will
you need something a bit more robust like CRC16?

Regards

John Samperi

********************************************************
Ampertronics Pty. Ltd.
11 Brokenwood Place Baulkham Hills, NSW 2153 AUSTRALIA
Tel. (02) 9674-6495 Fax (02) 9674-8745
Email: john@ampertronics.com.au
Website http://www.ampertronics.com.au
*Electronic Design * Custom Products * Contract Assembly
********************************************************



         

 
---------------------------------
The fish are biting.
 Get more visitors on your site using Yahoo! Search Marketing.

[Non-text portions of this message have been removed]

Re: [AVR-Chat] checksum

2007-03-13 by Richard Austin

You're using string1 ie.'i < strlen(string1);' outside the loop and 
string inside it 'sum = sum + string[i];'.

mago Umandam wrote:
Show quoted textHide quoted text
> Good idea... i checked the execution and of the for loop and it didnt go with the summation.  i checked again my for loop statement and i see a misplaced semicolon though far but was not commented out... HUHh... thus doing nothing on for loop:D
>    
>   thanks
>    
>   mago
> 
> Jim Wagner <jim_d_wagner@applelinks.net> wrote:
>           Have you checked the exection of the "for" loop in the
> debugger?
> 
> Jim
> 
> On 12 Mar 2007 22:10:47 -0700,Tue, 13 Mar 2007 05:10:11
> -0000
> "magzky02" <magzky02@yahoo.com> wrote:
> 
>>i would like to get the sum of values of characters in a
>>string. I 
>>use to get the checksum.
>>
>>ex.
>>strcopy(string1, "abcdefghigklmnopqrstuvwxyz");
>>
>>this does not work:
>>
>>sum=0;
>>for (i = 0; i < strlen(string1); i++)
>>{
>>sum = sum + string[i];
>>}
>>
>>but this works:
>>
>>sum = string1[0] + string1[1] + .... + string[25];
>>
>>but is too lengthy to do the later method.
>>is there any shorter method to get the sum of values in a
>>string? 
>>
>>regards
>>
>>mago
>>
> 
> 
> ----------------------------------------------------------
> The Think Different Store
> http://www.thinkdifferentstore.com/
> For All Your Mac Gear
> ----------------------------------------------------------
> 
> 
>          
> 
>  
> ---------------------------------
> Need Mail bonding?
> Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users.
> 
> [Non-text portions of this message have been removed]
> 
> 
> 
> 
>  
> Yahoo! Groups Links
> 
> 
> 
> 
> 
>

Re: [AVR-Chat] checksum

2007-03-13 by David Kelly

On Tue, Mar 13, 2007 at 02:30:40AM -0700, mago Umandam wrote:
> Good you mention about CRC. for now, i just get the sum and 2's
> compliment. But i look forward on doing CRC in the future. never did
> that yet :)

It may be easier to CRC as IIRC there is a CRC in avr-libc.

Be warned there are two schools of thought as to how the CRC should be
calculated.

-- 
David Kelly N4HHE, dkelly@HiWAAY.net
========================================================================
Whom computers would destroy, they must first drive mad.

Re: [AVR-Chat] checksum

2007-03-19 by Reza

--- Jim Wagner <jim_d_wagner@applelinks.net> wrote:

> Have you checked the exection of the "for" loop in
> the
> debugger?
> 
> Jim
> 
> 
> On 12 Mar 2007 22:10:47 -0700,Tue, 13 Mar 2007
> 05:10:11
> -0000
>  "magzky02" <magzky02@yahoo.com> wrote:
> > i would like to get the sum of values of
> characters in a
> > string. I 
> > use to get the checksum.
> > 
> > ex.
> > strcopy(string1, "abcdefghigklmnopqrstuvwxyz");
> > 
> > this does not work:
> > 
> > sum=0;
> > for (i = 0; i < strlen(string1); i++)
> > {
> > sum = sum + string[i];
> > }
> > 
> > but this works:
> > 
> > sum = string1[0] + string1[1] + .... + string[25];
> > 
> > but is too lengthy to do the later method.
> > is there any shorter method to get the sum of
> values in a
> > string? 
> > 
> > regards
> > 
> > mago
> > 
> 

ofcourse it's better to use end of string character,
instead of using strlen for each iteration:

sum = 0;
char c;

for(i=0; (c=s[i]) != '\0'; i++)
   sum += c;




 
____________________________________________________________________________________
Looking for earth-friendly autos? 
Browse Top Cars by "Green Rating" at Yahoo! Autos' Green Center.
http://autos.yahoo.com/green_center/

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.