Calculating a checksum


Closed Thread
Results 1 to 5 of 5

Hybrid View

  1. #1
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    967


    Did you find this post helpful? Yes | No

    Default

    If you're not too keen on saving up on the transmitted bytes, this is the easy way out.

    Code:
    MyString:    var   byte[30]           ' this is where the string will lie
    CheckSum:  var   word               ' quite obvious, eh?
    
    LocalCnt:     var   byte                ' a counter
    
    Checksum_it:
              CheckSum = 0                  ' start with 0
              for LocalCnt = 1 to 30       ' change this to suit the length of string 
                                                       ' you will parse
                       ' add the value of the character you read to checksum
                       ' after removing the ascii bias of character '0'
                       Checksum = Checksum + MyString[LocalCnt]-$30
              next
              return                            ' your checksum is cooked and ready to eat :)
    
    main:
              gosub CheckSum_it
              gosub  SendTheString           ' you might be having this
              hserout [Checksum]              ' send the checksum
     
              goto main

    This code is a concept - not tested or certified. It may not work as I am rusty these days. Too little rain with high humidity does this often

    Use this as a guide to refine your thoughts
    Good luck

  2. #2
    Join Date
    Apr 2009
    Posts
    4


    Did you find this post helpful? Yes | No

    Default

    Thank you!

Similar Threads

  1. NMEA CheckSum Routine
    By Tom Gonser in forum Code Examples
    Replies: 2
    Last Post: - 6th June 2015, 22:24
  2. 4 Bytes one button press
    By Dennis in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 15th January 2010, 22:36
  3. Checksum
    By retepsnikrep in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 24th October 2009, 04:09
  4. Creating Checksum in PBP
    By Tom Gonser in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 16th March 2005, 04:49
  5. Checksum problem!
    By atomski in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 3rd November 2004, 07:21

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts