programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Jeanne Boyarsky
• Ron McLeod
• Liutauras Vilda
• Paul Clapham
Sheriffs:
• paul wheaton
• Tim Cooke
• Henry Wong
Saloon Keepers:
• Stephan van Hulst
• Tim Holloway
• Carey Brown
• Frits Walraven
• Piet Souris
Bartenders:
• Mike London

# Check Sum -- 16 bit sum with out carry check word

Greenhorn
Posts: 2
• Number of slices to send:
Optional 'thank-you' note:
I have a requirement to create a checksum of a set of 16bit words by summing these words without carry checkword. Can any one provide guidance and/or code.

Not sure the best way to perform the "without carry" requirement.

thanks!!!

Master Rancher
Posts: 43045
77
• Number of slices to send:
Optional 'thank-you' note:
Welcome to JavaRanch.

I'm not sure what you mean by "without carry" - if you don't want one, don;t calculate one.

What datatype are the values in - if it's an int (which is a 32 bit type) then you'll have no problem with numbers being negative, and you can simply add them up in either an int or a long.

If the values are of type short (which is 16 bit) then the values could be negative. You'd need to check the most significant bit, and if it's set, treat the number especially before adding it to the sum.

Patrick Walter
Greenhorn
Posts: 2
• Number of slices to send:
Optional 'thank-you' note:

I'm not sure what you mean by "without carry" - if you don't want one, don;t calculate one.

I am using short (16 bit) values. Acually bytes. Requirement is to create a 16 bit check sum with "no carryover".

What do you mean by "check the most significant bit, and if it's set, treat the number especially before adding it to the sum. "
How do I "treat" the number.

example code would help....

thanks!!!

Ulf Dittmer
Master Rancher
Posts: 43045
77
• Number of slices to send:
Optional 'thank-you' note:
I was talking about 16 bit numbers where the most significant bit (MSB) is set , i.e., negative numbers as far as the Java short type is concerned. Since their actual value is between 32768 and 65536 (and not between -32768 and -1 as Java would think) you'd need to handle them especially.

But since you're adding bytes, this can't happen. The only thing to watch out for is if the sum becomes larger than 32767 because a short type will then become negative. This may be impossible unless you have a lot of numbers you're adding up, though.

 With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.