The Artima Developer Community
Sponsored Link

Python Buzz Forum
Generating Motorola S19 checksums in Python

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Phillip Pearson

Posts: 1083
Nickname: myelin
Registered: Aug, 2003

Phillip Pearson is a Python hacker from New Zealand
Generating Motorola S19 checksums in Python Posted: Dec 4, 2005 3:47 PM
Reply to this message Reply

This post originated from an RSS feed registered with Python Buzz by Phillip Pearson.
Original Post: Generating Motorola S19 checksums in Python
Feed Title: Second p0st
Feed URL: http://www.myelin.co.nz/post/rss.xml
Feed Description: Tech notes and web hackery from the guy that brought you bzero, Python Community Server, the Blogging Ecosystem and the Internet Topic Exchange
Latest Python Buzz Posts
Latest Python Buzz Posts by Phillip Pearson
Latest Posts From Second p0st

Advertisement

A friend just popped up on MSN and asked me how to generate S19 checksums in Python. It's a pretty trivial bit of code, but I know I'll want it again, or maybe someone is out there googling for a way to do it, so here we go:

def s19_checksum(line):
    length = eval("0x" + line[2:4])
    bytes = [eval('0x' + line[i*2:i*2+2]) for i in range(1, length+1)]
    return ~reduce((lambda a,b: a+b), bytes) & 0xff

for s in ('S1130170707172737475767778797A7B7C7D7E7F03',
 'S111FE7B59597B0173F6014A7B0146B7573093',
 'S106FE891B823D98',
 'S109F8020107DF01BA0D6C',):
    print "* checksumming %s" % s
    print "checksum: %s (compare with %s)" % (hex(s19_checksum(s)), s[-2:])

Comment

Read: Generating Motorola S19 checksums in Python

Topic: Wordpress Plugins - writing extra elements into RSS feeds Previous Topic   Next Topic Topic: Python hasn't held my interest

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use