473,320 Members | 1,732 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 2479
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Mercuro | last post by:
Hello i'm looking for a simple way to checksum my data. The data is 70 bytes long per record, so a 32 byte hex md5sum would increase the size of my mysql db a lot. I'm looking for something...
2
by: pradeep | last post by:
I have 2 data files, DATA1 and DATA2 , both same. My task is to: Open DATA1, compute the checksum and put it in the end of the file(don't bother about boundary conditions).close DATA1 Open...
4
by: Abby | last post by:
I have an array which contain Hex no. in each position. For examples, unsigned char data; data = 0x00; data = 0x01; data = 0x02; data = 0xE; data = 0xEF; --> This is the checksum value
2
by: Abby | last post by:
I need to do 8 bits 2's complement checksum, so I wrote code in order to see if the checksum calculation is correct. ===========================================================================...
9
by: UnixUser | last post by:
I am looking for some source code to run on Linux that will enable me to calculate and return a CRC32 value from a string of text. I have found one from snippets.org, but I cannot get it to...
6
by: Kevin | last post by:
I'm on Sun 0S 5.8 and need to calculate the checksum of certain sections in an ELF binary file. Specifically .text to .rodata. I'm able to parse through to the program header table and then find...
1
by: Terry | last post by:
I'm trying to calculate the checksum for UDP packet. The algorithm itself is not difficult (lots of examples out there), but what I'm having the most trouble with is determining the byte order...
34
by: Zahid Faizal | last post by:
Kindly suggest a good opensource package (in C or C++) that can compute the checksum of a file. SHA2 would be preferable, but SHA1/SHA0/MD5 would be acceptable as well. We have cards with...
4
by: Rain | last post by:
hi, need help here, does anyone know how to use or does any one have the code for checksum? I want to checksum a string to be sent using udp and checksum it again when received.. does anyone...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.