Click here to Skip to main content
15,902,886 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
i have a byte array of 1024 size that contains decimal values. i want to add all values stored in the array. and want to calculate check sum.
Posted
Comments
BillWoodruff 8-Nov-13 10:25am    
Your question is confusing: bytes represent integer values, not decimal. And it's very doubtful you'd have a byte array size #1024 which contained representations of .NET's decimal number Type.

Please clarify.
Matt T Heffron 8-Nov-13 13:00pm    
I'd GUESS that OP might have ASCII digits in each byte...
bunty swapnil 9-Nov-13 0:48am    
i have a byte array of 1024 size.

byte[] datablock_appenddataIntoByte = StringToByteArray(datablock_appenddata);

and datablock_appenddata contains string of hex numbers.

and hexnumbers like:-B80C001061020000690200006B020000

i want to calculate check sum through crc-32.

1 solution

That's really a simple task: just iterate on all values adding each of it to a global sum variable. Computing che checksum is simple as well, once you know the checksum algorithm you have to use (see, for instance "Checksum" page at Wikipedia[^]).
 
Share this answer
 
Comments
bunty swapnil 8-Nov-13 6:16am    
can u write code for addition.

byte[] datablock_appenddataIntoByte = StringToByteArray(datablock_appenddata);

this byte array contains 1024 bytes from 0-1023. i want to add all.
CPallini 8-Nov-13 6:24am    
What's the problem?
int sum=0; foreach( byte b in array) sum += b;
bunty swapnil 8-Nov-13 6:51am    
cpallini
can you help me to calculate check sum for this byte array.
Andreas Gieriet 8-Nov-13 7:28am    
Is this a homework assignment and you are too lazy to read the text book? Skipped any earlier exercises of your training program?
Andi

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900