[prev in list] [next in list] [prev in thread] [next in thread] 

List:       nsbasic-palm
Subject:    Re: [nsbasic-palm] CRC16 CCITT
From:       Douglas Handy <dhandy1 () bellsouth ! net>
Date:       2005-05-27 19:03:50
Message-ID: bfqe9152bpnrsh0m5r36u0kn5jbsr1616t () 4ax ! com
[Download RAW message or body]

Montse,
 
>How can I calculate the CRC16 CCITT?

I'm not familiar with the various forms of CRC algorithms.  The Bits N Bytes
Library has a CRC32 routine available.  And Palm OS has a sys trap which
computes a "16-bit CRC of a data block using the table lookup method".

I have no idea if that is the same as CCITT or not.

Judging from the SDK docs, I'd surmise you could use it from NSB/Palm by doing
this:

Function CalcCRC16( text As String, seed As Short ) as Short

  Dim crc		As Short
  Dim size	As Short

  size = StrLen( text )	'Maybe have to add 1 to this value?
  crc = SysTrapFunc( 601, 3, text, size, seed )	'Crc16CalcBlock()

  CalcCRC16 = crc

End Function

Any you could use it by doing something like this:

 myCrc = CalcCRC16( "Now is the time for all good men...", 0 )

I'll make the following disclaimers about the above:

 1) I have no idea if the "table lookup method" is the same as CCITT
 2) I don't know if you need to include the null terminator in the size
	calculation above, or even if it will make a difference.  If the CRC
	is just a modulus from summing all the bytes, it won't matter.  But
	if the CRC weights different positions the way a barcode or credit
	card number check does, than including the null at the end may
	impact the final result.
 3) The SDK docs say the CRC result is an unsigned 16-bit integer,
	but NSB/Palm has no unsigned numeric variables.  Therefore
	if the CRC is 32768-65535, it will come back to you as if it were
	a negative number from -32768 to -1
 4) The above will only work on a string with no embedded nulls,
	since NSB/Palm has no support for any variable type which 
	acts as a buffer.  You can include or exclude the string's 
	trailing null terminator by changing the "size" test above.
	But if you are trying to do a CRC on say a complete UDT or
	something, you can't do that with the above code.
 5) YMMV

Doug.



Complete Searchable Archive:
 http://marc.theaimsgroup.com/?l=nsbasic-palm&r=1&w=2

Shortcut URL to this page:
 http://groups.yahoo.com/group/nsbasic-palm  
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/nsbasic-palm/

<*> To unsubscribe from this group, send an email to:
    nsbasic-palm-unsubscribe@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic