CHECKSUM/de
From MCS Wiki AVR
< CHECKSUM(Difference between revisions)
(Created page with "= <span class="f_Header">Action</span> = Returns a checksum of a string. <span style="font-family: Arial;"> </span> <span style="font-family: Arial;"> </span> = ...") |
m (1 revision) |
Latest revision as of 21:13, 15 February 2013
Contents |
= (**COPIED FROM ENGLISH PAGE**) === Action
Returns a checksum of a string.
Syntax
PRINT Checksum(var)
b = Checksum(var)
b = ChecksumXOR(var)
Remarks
Var |
A string variable. |
B |
A numeric variable that is assigned with the checksum. |
The checksum is computed by counting all the bytes of the string variable.
The checksumXOR is computed by Xor-ing all the bytes of the string variable.
Checksums are often used with serial communication.
The checksum is a byte checksum. The following VB code is equivalent :
Dim Check as Byte
Check = 0
For x = 1 To Len(s$)
Check = check + ASC(mid$(s$,x,1))
Next
The following VB code is equivalent for ChecksumXOR
Dim Check as Byte
Check = 0
For x = 1 To Len(s$)
Check = check XOR ASC(mid$(s$,x,1))
Next
See also
Example
$regfile = "m48def.dat" ' specify the used micro $crystal = 8000000 ' used crystal frequency $baud = 19200 ' use baud rate $hwstack = 32 ' default use 32 for the hardware stack $swstack = 10 ' default use 10 for the SW stack $framesize = 40 ' default use 40 for the frame space Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0 Dim S As String * 10 'dim variable S = "test" 'assign variable Print Checksum(s) 'print value (192) End
Languages | English • Deutsch |
---|