470,874 Members | 1,787 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,874 developers. It's quick & easy.

looking for a checksum routine in C

Hi,

I'm looking for a way to calculate a checksum for a block of memory,
I'd like to use a readable two char(0..9, A..Z) to represent this
checksum, so the checksum should be less than 1296. I'm looking at
crc8, its result is 8 bits, that's only 256, crc16's result is 65535,
that's more than what the two char can accommodate, any idea how to
achieve this? even less than 1296, 1024 will do.

Thanks,

Angelo
Jun 27 '08 #1
10 2360
Angelo Chen <an***********@gmail.comwrote:
I'm looking for a way to calculate a checksum for a block of memory,
I'd like to use a readable two char(0..9, A..Z) to represent this
checksum, so the checksum should be less than 1296. I'm looking at
crc8, its result is 8 bits, that's only 256, crc16's result is 65535,
that's more than what the two char can accommodate, any idea how to
achieve this? even less than 1296, 1024 will do.
So what you want is basically a CRC-10, and the quality won't need to be
fabulously high since, with those specs, you're not going to share your
CRCs with anybody else.

I strongly suspect a websearch on CRC-10 would be helpful to you.

Richard
Jun 27 '08 #2
Angelo Chen wrote:
I'm looking for a way to calculate a checksum for a block of memory,
I'd like to use a readable two char(0..9, A..Z) to represent this
checksum, so the checksum should be less than 1296. I'm looking at
crc8, its result is 8 bits, that's only 256, crc16's result is 65535,
that's more than what the two char can accommodate, any idea how to
achieve this? even less than 1296, 1024 will do.
I would use a 16- or 32-bit CRC and then reduce mod 1296.

--
Thad
Jun 27 '08 #3
On Jun 19, 9:34*pm, Thad Smith <ThadSm...@acm.orgwrote:
I would use a 16- or 32-bit CRC and then reduce mod 1296.
That's one solution, but Richard suggests crc10, that's a good
approach too, I'm still searching for any sample code, so far, none
working code turned out.
Jun 27 '08 #4
Angelo Chen wrote:
On Jun 19, 9:34*pm, Thad Smith <ThadSm...@acm.orgwrote:
>I would use a 16- or 32-bit CRC and then reduce mod 1296.

That's one solution, but Richard suggests crc10, that's a good
approach too, I'm still searching for any sample code, so far, none
working code turned out.
What about the CRC code at:

<http://c.snippets.org/browser.php>
<http://www.ross.net/crc/links.html>

Jun 27 '08 #5
On Jun 19, 8:56*pm, r...@hoekstra-uitgeverij.nl (Richard Bos) wrote:
I found a code : http://www.packet.cc/files/CRC-10-code-ex.html, this
works. now, any tips on how to pack a number which is less than 1024
into a two byte char in the range of 0..9, A..Z?

Thanks
Jun 27 '08 #6
On Thu, 19 Jun 2008 07:45:43 -0700, Angelo Chen wrote:
I found a code : http://www.packet.cc/files/CRC-10-code-ex.html, this
works. now, any tips on how to pack a number which is less than 1024
into a two byte char in the range of 0..9, A..Z?

#define BASE32 "0123456789ABCDEFGHIJKLMNOPQRSTUV"
{
char str[2];
int crc= crc10( data );

str[0]= BASE32[ crc & 0x1f ];
str[1]= BASE32[ crc >5 ];
}

Jun 27 '08 #7
On Thu, 19 Jun 2008 07:34:05 -0600, Thad Smith wrote:
I would use a 16- or 32-bit CRC and then reduce mod 1296.
Not necessarily very safe. You would need to investigate the type of CRC
to see that it didn't, eg, treat the data as words and so using modulo
(especially modulo a non-prime with only two bits set) might discard all
information about certain bits in each input word.

Jun 27 '08 #8
On Jun 19, 11:00*pm, viza <tom.v...@gmil.comwrote:
On Thu, 19 Jun 2008 07:45:43 -0700, Angelo Chen wrote:
#define BASE32 "0123456789ABCDEFGHIJKLMNOPQRSTUV"
{
* char str[2];
* int crc= crc10( data );

* str[0]= BASE32[ crc & 0x1f ];
* str[1]= BASE32[ crc >5 ];

}
thanks, that finally solves the problem. case closed:)
Jun 27 '08 #9
Angelo Chen wrote:
r...@hoekstra-uitgeverij.nl (Richard Bos) wrote:

I found a code : http://www.packet.cc/files/CRC-10-code-ex.html,
this works. now, any tips on how to pack a number which is less
than 1024 into a two byte char in the range of 0..9, A..Z?
Those char sets can represent 36 values each, so you can represent
any number less that 36 * 36.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.

** Posted from http://www.teranews.com **
Jun 27 '08 #10
Angelo Chen wrote:
>
I'm looking for a way to calculate a checksum for a block of memory,
I'd like to use a readable two char(0..9, A..Z) to represent this
checksum, so the checksum should be less than 1296. I'm looking at
crc8, its result is 8 bits, that's only 256, crc16's result is 65535,
that's more than what the two char can accommodate, any idea how to
achieve this? even less than 1296, 1024 will do.
Use the 16 bit crc, such as CCIT. You can always display it as 4
hex chars. In addition, pay attention to whether you want to
detect errors in leading blocks of zeroes, which requires
initializing the crc to 0xffff.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
** Posted from http://www.teranews.com **
Jun 27 '08 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by Mercuro | last post: by
2 posts views Thread by pradeep | last post: by
2 posts views Thread by Abby | last post: by
9 posts views Thread by UnixUser | last post: by
6 posts views Thread by Kevin | last post: by
1 post views Thread by Terry | last post: by
34 posts views Thread by Zahid Faizal | last post: by
4 posts views Thread by Rain | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.