Thanks for the reply.

I do have the C code that does this. If anybody can easily translate it to PHP, it would be very apriciated.

Here is the C code. There is a decode function, but I don't need it in PHP because I have a C program listening to serial port on the other end that will validate the checksum.


/*
* operator fletcher_encode
*/
fletcher_encode( buffer, count )
unsigned char* buffer;
long count;
{
int i;
unsigned char c0 = 0;
unsigned char c1 = 0;
* ( buffer + count - 1 ) = 0;
* ( buffer + count - 2 ) = 0;
for( i = 0; i < count; i++)
{
c0 = c0 + * ( buffer + i );
c1 =c1 +c0;
}
* ( buffer + count - 2 ) = c0 - c1;
* ( buffer + count - 1 ) = c1 - 2*c0;
}


My problem with PHP was with the unsigned char.

Thanks again,

Dave Gervais



Ford, Mike [LSS] wrote:

-----Original Message-----
From: Dave Gervais [mailto:[EMAIL PROTECTED]]
Sent: 08 January 2003 19:11

Does anybody know how to implement the 8 and 16 bit versions of Fletcher's checksum using PHP? I hit google and came up dry. It's easy enough to find how to do it in C, but PHP if a different story.

Well, I have no idea what Fletcher's checksum is, but if you have a version
in C that's not too long (<20 lines of code, say), it shouldn't be too
difficult to convert it into PHP. There should be enough people here
sufficiently proficient in both C and PHP to at least give you a pointer in
the right direction!

Cheers!

Mike

---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS, LS6 3QS, United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to